tkinter问卷有警告

时间:2018-04-12 14:50:51

标签: tkinter tkinter-menu

import tkinter as tk
from tkinter import Frame, Button
LARGE_FONT= ("Venom Rockets", 12)

def confirm():
    confirm = "Confirmed" + str(var.get())
    label.config(text = selection)

class config_panel(tk.Tk):

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

        tk.Tk.__init__(self, *args, **kwargs)
        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 (MenuPage, Page1, Page2):
            frame = F(container, self)
            self.frames[F] = frame
            frame.grid(row=0, column=0, sticky=W)

        self.show_frame(MenuPage)

    def show_frame(self, cont):
        frame = self.frames[cont]
        frame.tkraise()

class MenuPage(tk.Frame):

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

        button = tk.Button(self, text="Abort", fg="red", command=quit)
        button.pack()
        button1 = tk.Button(self, text="Start Configuration",
                            command=lambda: controller.show_frame(Page2))

class Page1(tk.Frame):

    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        label = tk.Label(self, text="Configuration Page 1", font=LARGE_FONT)
        label.pack(pady=10,padx=10)
        labl1 = tk.Label(self, text="Please confirm launch location", front=LARGE_FONT)
        label1.pack(pady=10,padx=10)
        R1 = Radiobutton(root, text="LC39A.",
                         command=sel)
        R1.pack(anchor=W)
        R2 = Radiobutton(root, text="LC39B.",
                         command=sel)
        R2.pack(anchor=W)
        R3 = Radiobutton(root, text="LC49.",
                         command=sel)
        R3.pack(anchor=W)
        R4 = Radiobutton(root, text="LC13.",
                         command=sel)
        R4.pack(anchor=W)
        R5 = Radiobutton(root, text="LC37B.",
                         command=sel)
        R5.pack(anchor=W)
        R6 = Radiobutton(root, text="LC40.",
                         command=sel)
        R6.pack(anchor=W)
        R7 = Radiobutton(root, text="LC41.",
                         command=sel)
        R7.pack(anchor=W)
        R8 = Radiobutton(root, text="LC47.",
                         command=sel)
        R8.pack(anchor=W)
        Nextbtn = tk.Button(self, text="Confirm, Next.",
                            command=lambda: controller.show_frame(Page2))
        Nextbtn.pack()

class Page2(tk.Frame):
    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        label = tk.Label(self, text="Configuration Page 2", front=LARGE_FONT)
        label.pack(pady=10,padx=10)
        label1 = tk.Label(self, text="Please confirm rocket direction", front=LARGE_FONT)
        label1.pack(pady=10,padx=10)
        R1 = Raidobutton(root, text="North.",
                         command=sel)
        R1.pack(anchor=W)
        R2 = Radiobutton(root, text="East.",
                         command=sel)
        R2.pack(anchor=W)
        R3 = Radiobutton(root, text="South.",
                         command=sel)
        R3.pack(anchor=W)
        R4 = Radiobutton(root, text="West.",
                         command=sel)
        R4.pack(anchor=W)
        Nextbtn = tk.Button(self, text="Confirm, Next.",
                            command=lambda: controller.show_frame(MenuPage))
        Nextbtn.pack()

app = config_panel()
app.mainloop()

这是我目前所有的代码,但是我收到了这个错误:

Traceback (most recent call last):
  File "C:/Users/Samuel Berlet/Desktop/rfnirfi.py", line 105, in <module>
    app = config_panel()
  File "C:/Users/Samuel Berlet/Desktop/rfnirfi.py", line 24, in __init__
    frame = F(container, self)
  File "C:/Users/Samuel Berlet/Desktop/rfnirfi.py", line 37, in __init__
    tk.Frame.__init(self, parent)
AttributeError: type object 'Frame' has no attribute '_MenuPage__init' 

当我尝试运行它时。我想做一个问卷调查。就像会有一个菜单页面配置或中止中止将关闭整个事情配置将打开另一个窗口,将有问题的set1(发布位置),然后在那之后设置2等。如何做到这一点请有人可以帮助我使用代码。

1 个答案:

答案 0 :(得分:0)

在追溯的最后一行中,在__之后和之后放置双下划线(__init__)。您的代码中还有其他问题。