【问题标题】:How to use an image in tkinter [duplicate]如何在 tkinter 中使用图像 [重复]
【发布时间】:2016-08-28 23:53:36
【问题描述】:

我想在我的窗口中制作一个横幅,放在顶部。我将如何导入图像?如果有帮助,这里是我的代码。另外作为旁注,我删除了我尝试过的代码。我尝试将图像放入存储我的代码的文件中,然后尝试访问它。那是错误的方法吗?我知道这里有这样的例子,但它们对我不起作用,所以我发布了我的代码以获得更直接的响应

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()

【问题讨论】:

    标签: image user-interface python-3.x tkinter


    【解决方案1】:

    使用照片图像

    这是文档http://effbot.org/tkinterbook/photoimage.htm

    【讨论】:

      猜你喜欢
      • 2020-04-19
      • 2017-12-24
      • 1970-01-01
      • 1970-01-01
      • 2011-03-22
      • 2020-12-24
      • 1970-01-01
      • 1970-01-01
      • 2022-06-27
      相关资源
      最近更新 更多