I'm writing a simple Python 3 program using tkinter
. it should display a background picture and a button.
Here is the code:
import tkinter
from PIL import Image
from PIL import ImageTk
window = tkinter.Tk()
file = Image.open('/Users/dariushmazlumi/Desktop/p.jpg')
img = ImageTk.PhotoImage(file)
background = tkinter.Label(window, image=img)
background.image = img
background.pack()
window.minsize(height=window.winfo_height(), width=window.winfo_width())
number = 0
def buttonclicked():
global number
number = number+1
button.configure(text=number)
button = tkinter.Button(window, text=0, command=buttonclicked)
button.grid(column=1, row=1)
window.mainloop()
Prior to this, I tried using button.pack()
, but it shows button under the image, not on it(maybe the image is not background).
Next, I tried using button.grid()
. It runs on the terminal with no error, but no visible output! It just runs. I don't know why.
I want my program to display an image and buttons on it (like a desktop for example).