2017-06-10 8 views
-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' 

私がチェックしたときには、ゲームウィンドウが開きますので、チェックボックスがあり、起動時に表示されるメニューでゲームを作っています全画面表示。私はプログラムを実行しようとすると、私はこのエラーを取得:はAttributeError:「NoneType」オブジェクトが属性「_root」を持っていない(私の場合は異なります)

AttributeError: 'NoneType' object has no attribute '_root'

+2

エラーのトレースバック全体を投稿してください。 –

+0

[TkinterラジオボタンIntVar属性エラー](https://stackoverflow.com/questions/27372105/tkinter-radiobutton-intvar-attribute-error)の重複の可能性あり –

答えて

1

問題は、あなたがルートウィンドウTk()を作成している前に、あなたがfs = IntVar()を定義しているということです。

注: あなたが二以上のウィンドウがToplevelウィジェットを使用表示したい場合には、複数のルートウィンドウにTk()を作成することは推奨されません。

常に1つのウィンドウだけが必要な場合は、フレームを使用してウィジェットのコンテンツを格納し、同じルートを使用している間にそれらを作成および破棄します。

+0

ありがとうございました!私はちょうどPythonで始まっているので、私は 'start'ボタンのコマンドはframe.destroyでなければならないと思いますか? frame.destroyコマンドもフレーム内のすべてを破棄しますか? – KingSpikey

+0

また、fs変数をdef(coverscreen)の外側で動作させるには、グローバル(fs)を使用しますか? – KingSpikey

+1

はい、グローバルを定義する必要があります。クラスを見てGUIを書く方が良いでしょう。さもなければ 'lambda'を見ることができるので、' coverscreen'の中から必要な値を渡して 'page'関数を呼び出すことができます。 –

関連する問題