|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 ~风介~ 于 2015-10-9 19:19 编辑
为什么图片显示不出来?
- import tkinter as tk
- class APP:
- def __init__(self,root):
- frame=tk.Frame(root)
- frame.pack(side=tk.LEFT)
- photo=tk.PhotoImage(file='D:\\python3.3.2\\18.gif')
- imglable=tk.Label(root,image=photo)
- imglable.pack()
- self.hi_there=tk.Label(root,text='欢迎来到yz工作室!')
- self.hi_there.pack()
- theButton=tk.Button(root,text='ok',command=self.callback)
- theButton.pack(padx=100,pady=100)
- def callback(self):
- print('great!')
- root=tk.Tk()
- app=APP(root)
- root.mainloop()
复制代码
问题在于,你在乱调用!
要么你调用方法,代码如下!!!!可以实现!!
- import tkinter as tk
- class APP:
- def __init__(self,root):
- self.frame=tk.Frame(root)
- self.frame.pack(side=tk.LEFT)
- self.photo=tk.PhotoImage(file='D:\\python3.3.2\\18.gif')
- self.imglable=tk.Label(root,image=self.photo)
- self.imglable.pack()
- self.hi_there=tk.Label(root,text='欢迎来到yz工作室!')
- self.hi_there.pack()
- theButton=tk.Button(root,text='ok',command=self.callback)
- theButton.pack(padx=100,pady=100)
- def callback(self):
- print('great!')
- root=tk.Tk()
- app=APP(root)
- root.mainloop()
复制代码
要么你用函数式的调用!!代码如下:
- import tkinter as tk
- class APP:
- def __init__():
- root=tk.Tk()
- frame=tk.Frame(root)
- frame.pack(side=tk.LEFT)
- photo=tk.PhotoImage(file='D:\\python3.3.2\\18.gif')
- imglable=tk.Label(root,image=photo)
- imglable.pack()
- hi_there=tk.Label(root,text='欢迎来到yz工作室!')
- hi_there.pack()
- theButton=tk.Button(root,text='ok',command=APP.callback)
- theButton.pack(padx=100,pady=100)
- root.mainloop()
- def callback():
- print('great!')
- APP.__init__()
复制代码
不要在类里面混着弄!!!
|
|