如何使用tkinter在另一个窗口/框架中显示功能输出/结果

时间:2017-05-06 09:15:51

标签: python tkinter

我目前正在尝试创建一个小型会计程序,其中用户应键入他的收入和扩展,程序应该对其进行计数并在一个非常框架中显示不同的交易。我坚持到这一点:到目前为止,我创建了6帧,用户可以用按钮切换。

当用户点击“第一次交易”按钮时,他可以输入一个ammount,然后在他点击“验证”后,ammount显示在按钮下面。

但是我希望ammount显示在框架“交易概述” 花了几个小时搜索网络后,我找不到在应用程序中的一个框架/窗口上显示功能输出的方法。谢谢你的支持。

class Finanzapp(tk.Tk):

    def get_page(self, classname):

        for page in self.frames.values():
            if str(page.__class__.__name__) == classname:
                return page
        return None

    def __init__(self, *args, **kwargs):

        tk.Tk.__init__(self, *args, **kwargs)

        tk.Tk.wm_title(self, "Finanz Manager V2")
        container = tk.Frame(self)

        container.pack(side="top", fill="both", expand = True)

        container.grid_rowconfigure(0, weight=1)
        container.grid_columnconfigure(0, weight=1)

        self.frames = {}

        for F in (StartPage, PageOne, PageTwo, PageThree, Pagefour, Pagefive):

            frame = F(container,self)

            self.frames[F] = frame

            frame.grid(row=0, column = 0, sticky="nsew")

        self.show_frame(StartPage)

    def show_frame(self, cont):

        frame = self.frames[cont]
        frame.tkraise()

class StartPage(tk.Frame):

    def __init__(self, parent, controller):
        self.controller = controller
        tk.Frame.__init__(self,parent)
        label = tk.Label(self, text="Start Page", font=LARGE_FONT)
        label.pack(pady=10,padx=10)

        button1 = ttk.Button(self, text="erste Buchung",
                           command=lambda: controller.show_frame(PageOne)) # add a page
        button1.pack()

        button2 = ttk.Button(self, text="Konten",
                           command=lambda: controller.show_frame(PageTwo)) # add a page
        button2.pack()

        button3 = ttk.Button(self, text="neue Buchung",
                           command=lambda: controller.show_frame(PageThree)) # add a page
        button3.pack()

        button4 = ttk.Button(self, text="Kategorien",
                           command=lambda: controller.show_frame(Pagefour)) # add a page
        button4.pack()

        button5 = ttk.Button(self, text="Übersicht",
                           command=lambda: controller.show_frame(Pagefive)) # add a page
        button5.pack()

        button6 = ttk.Button(self, text="Diagramm",
                           command=lambda: controller.show_frame(StartPage)) # add a page
        button6.pack()



class PageOne(tk.Frame):

    def __init__(self, parent, controller):
        self.controller = controller
        tk.Frame.__init__(self, parent)
        label = tk.Label(self, text="erste Buchung", font=LARGE_FONT)
        label.pack(pady=10,padx=10)

        button1 = ttk.Button(self, text="zurück",
                           command=lambda: controller.show_frame(StartPage)) # add a page
        button1.pack()

        def calc():
            monthly_earning = float(m_earning.get())




            labelresult1 = Label(self, text='gebucht: € %.2f' % monthly_earning).pack()            
            label1 = Label(self, text='Enter the amount').pack()
        m_earning=StringVar()
        earning=Entry(self, textvariable=m_earning).pack()   
        buttoncalc=Button(self,text='Buchen', command=calc).pack() 

class PageTwo(tk.Frame):

    def __init__(self, parent, controller):

        def get_page(self,PageOne):

            def print_it(self):

                page_one = self.controller.get_page("PageOne")
                value = page_one.monthly_m_earning.get()
                labelresult2 = Label(self, text='gebucht: € %.2f' % value).pack()

        self.controller = controller
        tk.Frame.__init__(self, parent)
        label = tk.Label(self, text="Konten", font=LARGE_FONT)
        label.pack(pady=10,padx=10)

        button1 = ttk.Button(self, text="zurück",
                           command=lambda: controller.show_frame(StartPage)) 
        button1.pack()

0 个答案:

没有答案