2017-10-21 3359 views
-3

我在窗口上做了3個按鈕。我選擇了主窗口應該有一個特定的背景圖像和全屏。python tkinter點擊按鈕打開新窗口

現在出現了問題。我想通過點擊按鈕3.

事情我tryd移動到一個新的窗口(頁)(與其他背景和其他的東西):

  1. 從Main.Info.travelhistry進口*

    • 我已將此添加到主窗口中打開,具有在按鈕3.點擊時,但我發現,打開第二個屏幕的代碼的新的Python的文件,如果我這樣做既Windows會運行主窗口時打開。
  2. 我在開頭添加了root1 = Tk(),在末尾添加了root1.mainloop(),並在它們之間添加了另一個窗口的代碼。但是這樣做也不起作用,它像上面那樣開放2個窗口。

這些都是我的嘗試,我不能找出更好的方法。我可以但背景保持不變。但我必須將新窗口的背景更改爲我製作的背景圖片...

任何想法我做錯了什麼?

from tkinter import * 
from tkinter.messagebox import showinfo 
from Main.Info.travelhistry import * 


def clicked1(): 
    bericht = 'Deze functie is uitgeschakeld.' 
    showinfo(title='popup', message=bericht) 


root = Tk() 
a = root.wm_attributes('-fullscreen', 1) 

#Hoofdmenu achtergrond 
C = Canvas(root, bg="blue", height=250, width=300) 
filename = PhotoImage(file = "test1.png") 
background_label = Label(root, image=filename) 
background_label.place(x=0, y=0, relwidth=1, relheight=1) 
C.pack() 


# Geen OV-chipkaart button 
b=Button(master=root, command=clicked1) 
photo=PhotoImage(file="button1.png") 
b.config(image=photo,width="136",height="53", background='black') 
b.place(x=310, y=340) 


#Buitenland button 
b2=Button(master=root, command=clicked1) 
photo1=PhotoImage(file="button2.png") 
b2.config(image=photo1,width="136",height="53", background='black') 
b2.place(x=490, y=340) 

#Reis informatie 
b3=Button(master=root) 
photo2=PhotoImage(file="button3.png") 
b3.config(image=photo2,width="136",height="53", background='black') 
b3.place(x=680, y=340) 

root.mainloop() 
root2.mainloop() 
+1

目前尚不清楚,從你的描述,但你是不是想開多個根'TK()'窗口,你是誰?你不應該那樣做:'Tk()'調用不僅僅是打開一個窗口,而是附加了一個Tcl解釋器的實例,你應該只有一個!如果你需要更多的窗戶,你需要使用Toplevel窗戶。 –

+0

是的,我試圖打開其中的兩個,它同時開放工作。我不想讓我只想點擊按鈕3後打開第二個Tk。我將搜索Toplevel教程。我從來沒有聽說過它。 –

回答

0

您不應該致電一個以上的Tk()窗口。

相反,tkinter有另一個部件叫做Toplevel,它可以用來生成一個新窗口。

爲例見下文:

from tkinter import * 

root = Tk() 

def command(): 
    Toplevel(root) 

button = Button(root, text="New Window", command=command) 
button.pack() 

root.mainloop() 
相關問題