问题描述
from tkinter import*
decision=0
fs = IntVar()
def coverscreen():
slide=Tk() #Init window
slide.title('The Castle of Redemption BETA') #Give window a title
frame=Frame(slide)
btn1=Button(slide,text='Start Game',command=slide.destroy) #Init 1st button
fsbox=Checkbutton(frame,text='Fullscreen',\
variable=fs, onvalue=1,offvalue=0)
img=PhotoImage(file='cover.gif') # Init picture
label = Label(image=img) # Init label that contains picture
label.image = img # keep a reference!
label.pack() # Places the label on the window
btn1.pack(side=BOTTOM,pady=5) # Places the 1st button on the window
fsbox.pack()
frame.pack(padx=50,pady=50)
slide.mainloop() # Starts the window
def page(name,b1,b2,write,f,fscreen):
slide=Tk() #Init window
if fscreen == 1:
slide.overrideredirect(True)
slide.geometry("{0}x{1}+0+0".format(slide.winfo_screenwidth(), slide.winfo_screenheight()))
slide.title(name) #Give window a title
btn1=Button(slide,text=b1,command=slide.destroy) #Init 1st button
btn2=Button(slide,text=b2,command=slide.destroy) #Init 2nd button
txt=Label(slide,text=write)# Init story text
img=PhotoImage(file=f) # Init picture
label = Label(image=img) # Init label that contains picture
label.image = img # keep a reference!
label.pack() # Places the label on the window
btn1.pack(side=BOTTOM,pady=5) # Places the 1st button on the window
btn2.pack(side=BOTTOM,pady=5) # Places the 2nd button on the window
txt.pack(side=TOP,pady=5) # Places the text on the window
slide.mainloop() # Starts the window
coverscreen()
page('Start','Continue','Go Back','Example Story Text.','cover.gif',fs.get()) #Example of the created function 'page'
我正在制作一个游戏,它在启动时出现一个带有复选框的菜单,选中时将全屏打开游戏窗口.当我尝试运行程序时出现此错误:
I am making a game with a menu that appears on startup that has a checkbox, that when checked will open the game window in fullscreen. When I try to run the program I get this error:
AttributeError: 'NoneType' 对象没有属性 '_root'
推荐答案
问题是你在创建根窗口之前定义了 fs = IntVar()
Tk()代码>.
The problem is that you are defining fs = IntVar()
before you have created the root window Tk()
.
注意:不建议创建多个根窗口 Tk()
,如果你想显示第二个或更多窗口,请使用 Toplevel
小部件.
Note:It is not recommended to create multiple root windows Tk()
, if you want to display a second or more windows use a Toplevel
widget.
如果您始终只想要一个窗口,那么使用框架来包含寡妇内容,然后使用相同的根创建和销毁这些内容.
If you only want a single window at all times then use frames to contain the widow contents then create and destroy those while using the same root.
这篇关于AttributeError: 'NoneType' 对象没有属性 '_root'(我的情况不同)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!