我正在编写包含5个屏幕的简单GUI巫婆。
我想配置基本类(tk.Frame
)并设置诸如几何图形,可调整大小,bg等选项。如何在我的代码中进行管理?
class FormApp(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, *kwargs)
container = tk.Frame(self)
container.configure('%dx%d+%d+%d' % (XRes,YRes,
(ClientWidth-XRes)/2,
(ClientHeight-YRes)/2-20))
container.self.resizable(0, 0)
container.pack(side="top", fill="both", expand = True)
container.grid_rowconfigure(0, weight=0)
container.grid_columnconfigure(0, weight=0)
self.frames = {}
for F in (PageOne, PageTwo, PageThree, PageFour, PageFive):
frame=F(container, self)
self.frames[F]=frame
frame.grid(row=0, column=0, sticky="nsew")
self.show_frame(PageOne)
def show_frame(self, cont):
frame = self.frames[cont]
frame.tkraise()
我遇到了错误:
Traceback (most recent call last): File "C:/Users/Vladimir/Desktop/python/!project/Five Windows.py", line 113, in <module>
app = FormApp() File "C:/Users/Vladimir/Desktop/python/!project/Five Windows.py", line 37, in __init__
(ClientHeight-YRes)/2-20)) File "C:\Program Files\Python36\lib\tkinter\__init__.py", line 1482, in configure
return self._configure('configure', cnf, kw) File "C:\Program Files\Python36\lib\tkinter\__init__.py", line 1472, in _configure
return self._getconfigure1(_flatten((self._w, cmd, '-'+cnf))) File "C:\Program Files\Python36\lib\tkinter\__init__.py", line 1460, in _getconfigure1
x = self.tk.splitlist(self.tk.call(*args))
_tkinter.TclError: unknown option "-700x960+610+40"
不是字符串
container.configure('%dx%d+%d+%d' % (XRes,YRes,
(ClientWidth-XRes)/2,
(ClientHeight-YRes)/2-20))
配置容器?
答案 0 :(得分:0)
不输入字符串
container.configure('%dx%d+%d+%d' % (XRes,YRes, (ClientWidth-XRes)/2, (ClientHeight-YRes)/2-20))
配置容器?'
不,不是。 .configure
是配置窗口小部件的方法,但是第一个参数必须是可配置选项之一(background
,borderwidth
等)。
如果要设置框架的宽度和高度,则需要配置width
和height
选项。
如果要设置主窗口的大小,则需要在根窗口实例上调用geometry
方法。在您的特定情况下,它将为self.geometry(...)
。