Python 2.7 Tkinter Code -
my tkinter code showing no problems when run nothing shows up. wrong?
i'm using python 2.7. it's supposed pizzeria game way
here code:
import tkinter tk tkinter import stringvar import ttk 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 = {} 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
this nothing, since reference mainloop
method of window
class
window.mainloop
you need create instance of window
class before call mainloop
w = window() w.mainloop()
Comments
Post a Comment