0

I'm trying to learn to use python TTK, i keep getting an error when adding a simple little image to a button, can be any image in the same file as the program. This is the code :

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

This is the error I am receiving and I don't know why!

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'

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685

1 Answers1

0

you are assigning values to the output of pack(), rather than to the output of the class instantiation. You need another line:

 # 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')
user.pack()
userEnt = ttk.Entry(window)
userEnt.pack()
# so on and so forth
Vince W.
  • 3,561
  • 3
  • 31
  • 59