我正在尝试在Tkinter中设置帧大小和帧(主窗口小部件)的位置。基于this answer,我将其添加到我的代码中:
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()
但是,这样做的时候我得到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"
我这样叫这个班:
root = Tk(className='derp')
root.columnconfigure(0, weight=1)
root.rowconfigure(0, weight=1)
f = GetWord(root)
root.mainloop()
我该如何解决这个问题?我希望框架从屏幕中央开始,然后从特定的窗口大小开始(现在它是全屏的,但我稍后会改变它)。谢谢!
答案 0 :(得分:5)
您需要使用字母“x”而不是“+”
master.geometry("%sx%sx%sx%s" % (screensize[0], screensize[1], screensize[2], screensize[3]))