10

I have a dual monitors set up (laptop screen and external monitor). My laptop screen is my primary display and external monitor is secondary. Both have different screen sizes.

In my python tkinter script, i have used winfo_screenwidth() and winfo_screenheight() to detect the screen width and height so that I can set the root window to become full screen.

Normally, when I run my script, the root window will be the size of my laptop screen. When i move the window to my extended monitor, I want it to auto adjust the width and height to match the external display's width and height.

Is this possible? Is there any way to check if the root window is in primary or secondary display?

Does winfo_screenwidth() detect the width and height of the secondary display?

EDIT: I am using Windows XP Pro 32 bit & Python 2.7.

martineau
  • 119,623
  • 25
  • 170
  • 301
Chris Aung
  • 9,152
  • 33
  • 82
  • 127
  • Just my opinion, but I think window resizing should be left to the user to decide. Making a window full-screen is just one mouse-click away, so why force it? – tobias_k Jul 19 '13 at 09:24
  • 1
    @tobias_k Sorry, i forgot to mentioned that i am using my custom window and disabled the normal window style by using `root.overrideredirect(1)`, so i don't have the default maximize button at the moment. – Chris Aung Jul 19 '13 at 11:26
  • Many answers here: http://stackoverflow.com/questions/3129322/how-do-i-get-monitor-resolution-in-python – User Jul 20 '13 at 07:34

1 Answers1

3

How I did it:

t = Tk() # new window
t.update()
t.attributes("-alpha", 00)
t.state('zoomed') # maximize the window
height= t.winfo_height() # ...
width= t.winfo_width()

But sadly I do not know of the location of the other screen. But I think you can do this

  1. create a new window
  2. use winfo_screenheight() and winfo_screenwidth() to find out about the original screen
  3. use geometry() to move the window around
  4. maximize the window (it should always maximize at the screen where it is)
  5. get geometry()
  6. if geometry is at (0, 0) it is the main screen, proceed with 3.
  7. you found another screen
User
  • 14,131
  • 2
  • 40
  • 59
  • you mean `t.state('zoomed')` will maximize the root window on the screen it is appearing the time the command is executed? For example, if the root window is on the main display, it will maximize according to the main display width and height and the same apply for secondary display? – Chris Aung Jul 20 '13 at 02:34
  • Exactly. I know this is what should happen under Windows. I can not speak for other Window managers. Maybe you can try it out and tell if it works. – User Jul 20 '13 at 07:00