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!

4
  • 2
    Should be "%sx%s+%s+%s" for width, height, left, right (note x instead of +) Commented Feb 17, 2013 at 15:55
  • @AntonKovalenko Oh, small mistake. You should add that as an answer. Also, how can I center the frame? Commented Feb 17, 2013 at 15:58
  • You are already filling up the user's whole screen with the frame, I don't see a need to center it then. Commented Feb 17, 2013 at 16:02
  • @Siddharth I was just using the full-screen as an example. In my actual program, it will be about w/4 and h/4. Commented Feb 17, 2013 at 16:24

1 Answer 1

5

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

master.geometry("%sx%sx%sx%s" % (screensize[0], screensize[1], screensize[2], screensize[3]))
Sign up to request clarification or add additional context in comments.

1 Comment

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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.