我正在尝试在 Tkinter 中设置框架大小和框架(主小部件)的位置。根据这个答案,我将其添加到我的代码中:
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()
我怎样才能解决这个问题?我想让框架从屏幕的中心开始,并从特定的窗口大小开始(现在它是全屏的,但我稍后会改变它)。谢谢!