2

I am trying to set a frame-size and the location of the frame (master widget) in Tkinter. Based off of this answer, I added this to my code:

from Tkinter import *
import ctypes
user = ctypes.windll.user32
screensize = (user.GetSystemMetrics(0), user.GetSystemMetrics(1), user.GetSystemMetrics(2), user.GetSystemMetrics(3))

class GetWord:
    def __init__(self, master):
        master.geometry("%s+%s+%s+%s" % (screensize[0], screensize[1], screensize[2], screensize[3]))
        # I added the above in, but not sure how it works
        self.frame = Frame(master, width = screensize[0], height = screensize[1])
        self.frame.grid()

However, when doing this I get a TclError:

Traceback (most recent call last):
  File #file path, line 39, in <module>
    f = GetWord(root)
  File #file path, line 8, in __init__
    master.geometry("%s+%s+%s+%s" % (screensize[0], screensize[1], screensize[2], screensize[3]))
  File "C:\Python2.7.3\lib\lib-tk\Tkinter.py", line 1534, in wm_geometry
    return self.tk.call('wm', 'geometry', self._w, newGeometry)
TclError: bad geometry specifier "1366+768+17+17"

I call the class like this:

root = Tk(className='derp')
root.columnconfigure(0, weight=1)
root.rowconfigure(0, weight=1)
f = GetWord(root)
root.mainloop()

How can I fix this? I want to have the frame start off in the center of the screen and start at a specific window size (right now it's full-screen but I will change that later on). Thanks!

Community
  • 1
  • 1
Rushy Panchal
  • 16,979
  • 16
  • 61
  • 94

1 Answers1

5

You Need to use the letter "x" instead of "+"

master.geometry("%sx%sx%sx%s" % (screensize[0], screensize[1], screensize[2], screensize[3]))
Siddharth Gupta
  • 897
  • 5
  • 20
  • I'm generally going to use `screensize[0]/2` and `screensize[1]/2` as the parameters. How can I center the window in the middle of the screen? – Rushy Panchal Feb 17 '13 at 16:01