0
我想在窗口中打開一個橫幅以顯示在頂部。我將如何導入圖像?如果這有幫助,那就是我的代碼。另外作爲一個附註,我刪除了我試過的代碼。我試圖把圖像放在我的代碼存儲在文件中,然後試圖訪問它。這是錯誤的方法嗎?我知道在這裏的這個例子,但他們不爲我工作,所以我貼我的代碼,以獲得更直接的反應如何在tkinter中使用圖像
import tkinter
#create new window
window = tkinter.Tk()
#name window
window.title("Basic window")
#window sized
window.geometry("250x200")
#creates label then uses ut
lbl = tkinter.Label(window, text="Please sign up or log in ", bg="green")
#pack label
lbl.pack()
#create username
lbl_username = tkinter.Label(window, text="Username", bg="green")
ent_username = tkinter.Entry(window)
#pack username
lbl_username.pack()
ent_username.pack()
#attempting to get the ent_username info to store
#configure window
window.configure(background="red")
#basic enter for password
lbl_password = tkinter.Label(window, text="Password", bg="green")
ent_password = tkinter.Entry(window)
#pack password
lbl_password.pack()
ent_password.pack()
#def to check if username is valid
def question():
username = ent_username.get()
password = ent_password.get()
if username == "louis":
print("you know")
else:
print("failed")
if password == "2xfeikis":
print("it passed for pass")
else:
print("it failed for pass")
def sign_up():
username = ent_username.get()
password = ent_password.get()
if len(username) > 0 and len(password) > 0:
pass
else:
print("invalid info")
#will make the sign up button and will call question on click
btn = tkinter.Button(window, text="Log", command=lambda: question(), bg ="grey")
#sign up button
btn_sign_up = tkinter.Button(window, text="Sign up", command= lambda: sign_up(), bg ="grey")
#pack buttons
btn.pack()
btn_sign_up.pack()
#draw window
window.mainloop()