嗨我正在做这个Tkinter任务,我不知道为什么即使我把主循环放进去也不会运行。
# Importing Tkinter to display the graphics
import Tkinter
# Creating a class called StoryMaker
class StoryMaker:
# The initializer with the self parameter
def __init__(self):
# This creates the main window
self.main_window = Tkinter.Tk()
# This creates the three different frames for different widgets
self.top_frame = Tkinter.Frame(self.main_window)
self.mid_frame = Tkinter.Frame(self.main_window)
self.bottom_frame = Tkinter.Frame(self.main_window)
# Instructs the user to enter the information given to create the story
self.story_label = Tkinter.Label (self.top_frame, text = "Please enter the information given for the new story, then click the \"Make Story\" Button!" )
self.prompt_label1 = Tkinter.Label (self.top_frame, text = "Character Name: ")
self.get_prompt1 = Tkinter.Entry (self.top_frame, width = 10)
self.story_label.pack (side = 'left')
story.prompt_label.pack (side = 'left')
self.get_prompt1.pack (side = 'left')
self.prompt_label2 = Tkinter.Label (self.mid_frame, text = "Place: ")
self.get_prompt2 = Tkinter.Entry (self.mid_frame, width = 10)
self.prompt_label3 = Tkinter.Label (self.mid_frame, text = "Food: ")
self.get_prompt3 = Tkinter.Entry (self.mid_frame, width = 10)
self.radio_var = Tkinter.IntVar()
self.radio_var.set(1)
self.prompt_label4 = Tkinter.Label(self.mid_frame, text = "Hotels")
self.rb1 = Tkinter.Radiobutton(self.mid_frame, text = "Hilton", variable = self.radio_var, value = 1)
self.rb2 = Tkinter.Radiobutton(self.mid_frame, text = "Burj Al Arab", variable = self.radio_var, value = 2)
self.rb3 = Tkinter.Radiobutton(self.mid_frame, text = "Holiday Inn", variable = self.radio_var, value = 3)
self.rb1.pack()
self.rb2.pack()
self.rb3.pcak()
self.cb_var1 = Tkinter.IntVar()
self.cb_var2 = Tkinter.IntVar()
self.cb_var3 = Tkinter.IntVar()
self.cb_var1.set(0)
self.cb_var2.set(0)
self.cb_var3.set(0)
self.prompt_label5 = Tkinter.Label (self.mid_frame, text = "Foods")
self.cb1 = Tkinter.Checkbutton (self.top_frame, text = "Pizza", variable = self.cb_var1)
self.cb2 = Tkinter.Checkbutton (self.top_frame, text = "Spaghetti", variable = self.cb_var2)
self.cb3 = Tkinter.Checkbutton (self.top_frame, text = "Hamburger", variable = self.cb_var3)
self.cb1.pack()
self.cb2.pack()
self.cb3.pack()
self.create_button = Tkinter.Button(self.bottom_frame, text = "Create", command = self.story)
self.quit_button = Tkinter.Button(self.bottom_frame, text = "Quit", command = self.main_window.quit)
self.create_button.pack(side = 'left')
self.quit_button.pack(side = 'left')
self.top_frame.pack()
self.mid_frame.pack()
self.bottom_frame.pack()
Tkinter.mainloop()
my_gui = StoryMaker
答案 0 :(得分:1)
你最后一行实际上应该调用你所花费的所有时间构建的课程:
my_gui = StoryMaker()
了解这对您有何帮助。执行此操作将执行特殊的__init__()
方法,并运行GUI。