-2
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' object has no attribute '_root'

bastelflp
  • 9,362
  • 7
  • 32
  • 67

1 Answers1

1

The problem is that you are defining fs = IntVar() before you have created the root window Tk().

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.

Steven Summers
  • 5,079
  • 2
  • 20
  • 31
  • Thanks! i am just starting with Python, so i guess the command of the 'start' button should be frame.destroy? Would the frame.destroy command also destroy everything in the frame? – KingSpikey Jun 10 '17 at 05:36
  • Also, to get the fs variable to work outside the def(coverscreen) , i would use global(fs) right? – KingSpikey Jun 10 '17 at 05:37
  • 1
    Yes you would have to define a global, it would be better to look at classes for writing a GUI. Otherwise you could look at `lambda` so you can call the `page` function from inside `coverscreen` passing the required values. – Steven Summers Jun 10 '17 at 05:42