在Python中使用tkinter包装框架的问题

时间:2019-06-24 14:43:39

标签: python user-interface tkinter

我为2个不同的窗口提供2个类。在主窗口中,单击按钮,将打开第二个窗口。

我要在第二个窗口中打包的框架显示在第一个主窗口中。

LABEL2和“初始化”按钮(分类广告系列)出现在主窗口中,而其他所有按钮则出现在新的广告系列窗口中。我该如何解决?

此外,就最佳的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")

0 个答案:

没有答案