我正在编写包含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))
配置容器
不,没有
.configure
是配置小部件的方法,但第一个参数必须是可配置选项之一(background
,borderwidth
,等等)如果试图设置帧的宽度和高度,则需要配置
width
和height
选项如果试图设置主窗口的大小,则需要在根窗口实例上调用
geometry
方法。在您的特定情况下,它将是self.geometry(...)
相关问题 更多 >
编程相关推荐