Python 2.7 Tkinter Code



我的Tkinter代码显示没有问题,但当我运行它没有显示任何问题。怎么了?

我正在使用Python 2.7。这应该是一个披萨店游戏

下面是我的代码:
import Tkinter as tk
from Tkinter import StringVar
import ttk
from random import randint , choice ,uniform
class Window(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 (StartPage, Easy, Hard):
            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.Label(text = "Welcome!" , font = ("Verdana", 12)).pack()
    ttk.Button(text = "Play" , command = lambda: Window().show_frame(Play()))
class Play():
    def loop():
        q = randint(0, 10)
        p = uniform(1.50 , 10.50)
        t = uniform(.1, .9)
        p2 = p*q
        p3 = p2*t
        g = StringVar()
        ttk.Entry(textvariable=g).pack()
        ttk.Label(text = "Price Per Pizza: " + str(p) + " Amount: " + str(q) + " Tax: " + str(t))
        if g == p3 : ttk.Label(text = "Correct!")
        elif g != p3: ttk.Label(text = "Try Again.")
    loop()
    ttk.Button(text = "Play" , command = lambda: loop())
Window.mainloop

这没有任何作用,因为它只是对Window类的mainloop方法的引用

Window.mainloop

在调用mainloop之前需要创建一个Window类的实例

w = Window()
w.mainloop()

相关内容

  • 没有找到相关文章

最新更新