python - 在 Python 中使用 tkinter 打包帧的问题
问题描述
我有 2 个课程用于 2 个不同的窗口。在主窗口中,单击一个按钮会打开第二个窗口。
我试图在第二个窗口上打包的框架显示在第一个主窗口上。
LABEL2 和 Init 按钮(类活动)出现在主窗口中,而所有其他按钮出现在新活动窗口中。我怎样才能解决这个问题?
此外,就最佳 GUI 编程实践而言,这还好吗?
以下是代码
class MainWindow(tk.Frame):
def __init__(self, master):
HEIGHT = 500
WIDTH = 600
super(MainWindow, self).__init__()
self.canvas = tk.Canvas(self.master, height = HEIGHT, width = WIDTH)
self.canvas.pack()
self.FRAME = tk.Frame(self.master, bd = 5).place(relwidth=1, relheight =0.5, relx = 0, rely=0)
self.LABEL = tk.Label(self.FRAME, text="Keravalon BizDev").place(relwidth = 1, relheight = 0.05, relx=0,rely=0)
# Code to add widgets will go here...
self.B = tk.Button(self.FRAME, text ="Campaigns", command = lambda: self.campaign_win())
self.C = tk.Button(self.FRAME, text ="Analysis", command = self.helloCallBack)
self.B.place(relx = 0.5, rely = 0.1, anchor = 'n')
self.C.place(relx = 0.5, rely = 0.15, anchor = 'n')
def helloCallBack(self):
messagebox.showinfo( "Hello Python", "Hello World")
def campaign_win(self):
root_camp = tk.Tk()
app2 = campaigns(root_camp)
root_camp.mainloop()
class campaigns(tk.Frame):
def __init__(self, master):
super(campaigns, self).__init__()
self.FRAME2 = tk.Frame(self.master, width=100, height =50).place(x=700,y=0)
self.LABEL2 = tk.Label(self.FRAME2, text="Campaigns").pack()
# Code to add widgets will go here...
self.Init = tk.Button(self.FRAME2, text ="Initialize", command = self.helloCallBack)
self.Skr = tk.Button(master, text ="Update Skrapp", command = self.helloCallBack)
self.Hub = tk.Button(master, text ="Update HubSpot", command = self.helloCallBack)
self.Wood = tk.Button(master, text ="Update Woodpecker", command = self.helloCallBack)
self.Ex_NB = tk.Button(master, text ="Export for NeverBounce", command = self.helloCallBack)
self.NB = tk.Button(master, text ="Update NeverBounce", command = self.helloCallBack)
self.Ex_WP = tk.Button(master, text ="Export for Woodpecekr", command = self.helloCallBack)
self.Init.pack()
self.Skr.pack()
self.Hub.pack()
self.Wood.pack()
self.Ex_NB.pack()
self.NB.pack()
self.Ex_WP.pack()
def helloCallBack(self):
messagebox.showinfo( "Hello Python", "Hello World")
解决方案
推荐阅读
- android - 我可以以编程方式选择所有 Whatsapp 联系人,然后单击即可向他们发送消息
- jwt - 文档标题中不存在邮递员集合授权
- aforge - AForge.net 详尽模板匹配
- javascript - JS 应该选择我们使用 selected="selected" 的第二个选项
- javascript - 将父数组元素和子数组推入javascript中的新数组
- powershell - PowerShell 脚本:按对象大小(以 MB 为单位)排序
- android - 格式化为
带有空格和换行符的标签 Android
- asp.net - 在 ASP.Net 的母版页中创建注销按钮
- docker - docker命令相关的查询
- c++11 - 在 solaris 11 中为 gcc 设置 c++11 std