Python Tkinter图像未在类内显示
此线程已关闭: 编辑:问题的解决方案是,当我调用模块时,我没有主循环,导致图像只在一开始显示 我目前正在创建一个tkinter应用程序,并通过为我的不同页面提供它们自己的类和模块来整理一切。 发生的事情是,当我调试代码时,所有的图像都正常工作,直到我修复了这个错误 我只是说:Python Tkinter图像未在类内显示,python,class,tkinter,Python,Class,Tkinter,此线程已关闭: 编辑:问题的解决方案是,当我调用模块时,我没有主循环,导致图像只在一开始显示 我目前正在创建一个tkinter应用程序,并通过为我的不同页面提供它们自己的类和模块来整理一切。 发生的事情是,当我调试代码时,所有的图像都正常工作,直到我修复了这个错误 我只是说: Button (window, text="SUBMIT", width=8, command=Loginpage.change_home()).place(x = 220, y = 365) 这只是
Button (window, text="SUBMIT", width=8, command=Loginpage.change_home()).place(x = 220, y = 365)
这只是一个简单的问题,我刚刚忘记更改我函数的名称。但是当我修复它时,没有一个图像显示出来。它们没有错误消息或任何东西,其他一切正常,但图像没有显示
def __init__(self, window):
page = Frame(window)
window.geometry("500x430")
self.logo = PhotoImage(file="images\TheImage.pgm")
global loginresult
loginresult = Text(window, width=35, height=1, wrap=WORD, bg="black", fg="red", borderwidth=0)
def change(change_to):
return(change_to)
def change_home():
change_to = "home"
Loginpage.change(change_to)
def change_create():
change_to = "create"
Loginpage.change(change_to)
def login(self, window):
window.configure(background="black")
image = Label(window, image=self.logo, bg="black").pack(side="top")
Label (window, text="Username", bg="black", fg="white", font="none 12 bold").place(x=220,y=260)
Label (window, text="Password", bg="black", fg="white", font="none 12 bold").place(x=220,y=310)
textentryusername = Entry(window, width=50, bg="white")
textentrypassword = Entry(window, width=50, bg="white")
textentryusername.place(x=107,y=285)
textentrypassword.place(x=107,y=335)
username = textentryusername.get()
password = textentrypassword.get()
Button (window, text="SUBMIT", width=8, command=Loginpage.change_home()).place(x = 220, y = 365)
print(username + " " + password)
Button (window, text="Don't have an account?", width=18, command=Loginpage.change_create()).place(x = 185, y = 400)
loginresult.place(x=107,y=230)
编辑:对不起,我忘了添加我是作为模块运行的,这就是为什么我没有调用此页面上的函数
此外,我还列出了一个最小的可复制示例:
from tkinter import *
from PIL import Image, ImageTk
window = Tk()
class Loginpage:
def __init__(self, window):
page = Frame(window)
window.geometry("500x430")
self.logo = PhotoImage(file="Test.pgm")
def login(self, window):
image = Label(window, image=self.logo, bg="black").pack(side="top")
Loginpage(window).login(window)
在上面的示例中,我仍然遇到问题,没有错误消息或任何东西。乍一看,您似乎忘记调用login()方法。您的意思是要将
self.login()
添加到\uuuu init\uuu
的底部吗?您需要显示一个特定的帮助。乍一看,您似乎忘记调用login()方法。您的意思是要将self.login()
添加到\uuuu init\uuu
的底部吗?您需要显示一个特定的帮助。