Skip to content

Commit 27a78ff

Browse files
feat How To Use Images as Backgrounds
How To Use Images as Backgrounds resolve: see also:
1 parent dfd1a41 commit 27a78ff

File tree

4 files changed

+78
-0
lines changed

4 files changed

+78
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#####################################################################
2+
# Python Tkinter How To Use Images as Backgrounds
3+
# Python Tkinter Cómo usar imágenes como fondos
4+
#####################################################################
5+
6+
from tkinter import *
7+
8+
root = Tk()
9+
root.title('Python Tkinter How To Use Images as Backgrounds')
10+
root.iconbitmap('Python Tkinter How To Use Images as Backgrounds/icons/pikachu.ico')
11+
root.geometry("900x600")
12+
13+
# Define image
14+
bg = PhotoImage(file="Python Tkinter How To Use Images as Backgrounds/images/mario.png")
15+
16+
# Create a Label
17+
my_label = Label(root, image=bg)
18+
my_label.place(x=0, y=0, relwidth=1, relheight=1)
19+
20+
21+
# Add something to the of our image
22+
my_text = Label(root, text="Welcome!", font=("Helvetica", 50), fg="white", bg='#6b88fe')
23+
my_text.pack(pady=50)
24+
25+
# create frame
26+
my_frame = Frame(root, bg='#6b88fe')
27+
my_frame.pack(pady=20)
28+
29+
# add some buttons
30+
my_button1 = Button(my_frame, text="Exit")
31+
my_button1.grid(row=0, column=0, padx=20)
32+
33+
my_button2 = Button(my_frame, text="Start")
34+
my_button2.grid(row=0, column=1, padx=20)
35+
36+
my_button3 = Button(my_frame, text="Reset")
37+
my_button3.grid(row=0, column=2, padx=20)
38+
39+
root.mainloop()
40+
41+
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#####################################################################
2+
# Python Tkinter How To Use Images as Backgrounds 2
3+
# Python Tkinter Cómo usar imágenes como fondos
4+
#####################################################################
5+
6+
from tkinter import *
7+
8+
root = Tk()
9+
root.title('Python Tkinter How To Use Images as Backgrounds')
10+
root.iconbitmap('Python Tkinter How To Use Images as Backgrounds/icons/pikachu.ico')
11+
root.geometry("900x600")
12+
13+
# Define image
14+
bg = PhotoImage(file="Python Tkinter How To Use Images as Backgrounds/images/mario.png")
15+
16+
# Create a canvas
17+
my_canvas = Canvas(root, width=800, height=500)
18+
my_canvas.pack(fill="both", expand=True)
19+
20+
# Set image in canvas
21+
my_canvas.create_image(0,0, image=bg, anchor="nw")
22+
23+
# add label
24+
my_canvas.create_text(400, 250, text="Welcome!", font=("Helvetica", 50), fill="white")
25+
26+
# add some buttons
27+
button1 = Button(root, text="Start")
28+
button2 = Button(root, text="Reset Score")
29+
button3 = Button(root, text="Exit")
30+
31+
button1_window = my_canvas.create_window(10, 10, anchor="nw", window=button1)
32+
button2_window = my_canvas.create_window(50, 10, anchor="nw", window=button2)
33+
button3_window = my_canvas.create_window(130, 10, anchor="nw", window=button3)
34+
35+
root.mainloop()
36+
37+
Binary file not shown.
Loading

0 commit comments

Comments
 (0)