【发布时间】:2015-03-23 07:10:00
【问题描述】:
所以在我的代码中,我试图在第一帧(徽标页)上创建一个按钮,以便在单击时关闭该帧,然后打开另一个帧(介绍战斗)。但是,当前按下按钮时,第一帧被删除,但下一帧不显示,留下一个空白窗口。我认为正在发生的事情是下一帧出现了,但是由于它的所有小部件都是在帧被打包之前打包的,所以它们不会出现。我如何才能显示所有应该在下一帧中的小部件?这是代码。
############################## GUI GAME #############################
from tkinter import *
############################## PROGRAM #############################
class MyApp:
def __init__(self,parent):
################################## LOGO PAGE ###############################
self.myParent=parent
Pic1 = PhotoImage(file="../Python STUFF/RestLogo.gif") #logo
Pic2 = PhotoImage(file="../Python STUFF/IntroBattle.gif") #Intro Battle
self.LogoFrame=Frame(parent)
self.LogoFrame.pack()
self.b1=Button(self.LogoFrame, text=('Continue'),command = self.showIntro)
self.b1.pack(side='bottom')
self.w1 = Label(self.LogoFrame, image = Pic1)
self.w1.image=Pic1
self.w1.pack(side='top')
################################### INTRO FIGHT #############################
self.IntroFrame=Frame(parent)
self.IntroBG=Label(self.IntroFrame, image=Pic2)
self.IntroBG.image=Pic2
self.IntroBG.place(x=0,y=0)
self.text=Message(self.IntroFrame, fg='black',text="""Flaming Arrows whizz over your hair, War rages around you. Suddenly, it charges at you. A 8 foot tall mechanical beast the enemy have been training for war. You have no chance but to fight it. You swing your sword as hard as you can...Only to leave a minor dent on it's armor. With one blow from its club, you fall unconscious."""
, font='Times 15 bold')
self.text.place(x=70, y=50)
self.FinishSlide1=Button(self.IntroFrame, text='Next', command = self.WakingUp, width=10)
self.FinishSlide1.place(x=500, y=700)
def WakingUp(self): #Closes game for now
root.destroy()
def showIntro(self): #Transition into Intro Fight frame.
self.LogoFrame.destroy()
self.IntroFrame.place(x=0, y=0)
print ('\n'*100) #Clear Screen
root = Tk()
myapp=MyApp(root)
root.title('GUI GAME')
root.mainloop()
【问题讨论】:
标签: python tkinter command python-3.4