我正在为我的GUI在弹出窗口中放置小部件。我把复选框放在弹出窗口的顶部,我希望标签、条目和按钮在它们下面排成一行。无论我尝试什么,标签、条目和按钮总是放在复选框旁边。我还没有找到使用pack()
的解决方案。我试过anchor=
,但这也没有达到我想要的效果。在
这是我的代码:
import tkinter as tk
from tkinter import *
CheckVar1 = IntVar()
CheckVar2 = IntVar()
class PopUp(tk.Tk):
def __init__(self):
tk.Tk.__init__(self)
popup = tk.Toplevel(self, background='gray15')
popup.wm_title("EMAIL")
self.withdraw()
popup.tkraise(self)
self.c1 = tk.Checkbutton(popup, text="Current", variable=CheckVar1, onvalue =1, offvalue = 0, height=2, width=15)
self.c1.pack(side="left", fill="x")
self.c2 = tk.Checkbutton(popup, text="-1", variable=CheckVar2, onvalue =1, offvalue = 0, height=2, width=15)
self.c2.pack(side="left", fill="x")
label = tk.Label(popup, text="Please Enter Email Address", background='gray15', foreground='snow')
label.pack(side="left", fill="x", pady=10, padx=10)
self.entry = tk.Entry(popup, bd=5, width=35, background='gray30', foreground='snow')
self.entry.pack(side="left", fill="x")
self.button = tk.Button(popup, text="OK", command=self.on_button, background='gray15', foreground='snow')
self.button.pack(side="left", padx=10)
def on_button(self):
address = self.entry.get()
print(address)
time.sleep(10)
self.destroy()
app = PopUp()
app.mainloop
有什么东西我可以放进pack()
,这样我就可以把这些小部件放在一起,然后把另一个放在它们下面?在
提前谢谢
使用网格几何管理器将窗口划分为两个框架,然后将小部件打包到框架中。在
一些注意事项:
无需导入Tkinter两次
Mainloop是一种方法,因此应用程序主循环()
相关问题 更多 >
编程相关推荐