我正在尝试学习使用pythontttk,我在向按钮添加一个简单的小图像时不断出错,可以是同一文件中的任何图像程序。代码如下:
# from PIL import ImageTk, Image
from tkinter import *
from tkinter import ttk
from PIL import ImageTk, Image
window = Tk()
window.wm_iconbitmap('icon.ico')
window.geometry('200x200')
user = ttk.Label(window, text='Username').pack()
userEnt = ttk.Entry(window).pack()
passW = ttk.Label(window, text='Password').pack()
passEnt = ttk.Entry(window).pack()
logButton = ttk.Button(window, text='Login').pack()
myImg = PhotoImage(file='C:\\Users\edwin\Desktop\Python\Tkinter\logo.png')
logButton.config(image=myImg, compound=RIGHT)
window.mainloop()
这是我收到的错误,我不知道为什么!在
File "C:/Users/edwin/Desktop/Python/Tkinter/trial.py", line 18, in logButton.config(image=myImg, compound=RIGHT) AttributeError: 'NoneType' object has no attribute'config'
将值赋给pack()的输出,而不是类实例化的输出。你需要另一条线:
相关问题 更多 >
编程相关推荐