Edit: Re-wrote script and add image and tk.Photoimage
.
I can't import font and anchor. I updated python, but it's still not
working
I commented out the import font
and from tkinter import
. Actually, you don't need both.
Use import tkinter as tk
then tk
prefix.
Understanding how to to use ttk.Style()
. For instance, ttk.Button(win, ...,style='Heading.TButton')
#Heading.Tx .... x denote widget.
- In line 7, add
style = ttk.Style()
- In line 9, add
style.configure('Heading.TButton', font=('Arial', 21))
- In line 12, remove keyword
font=('Arial',21)
- In line 18, add
tk.Photoimage
.
- In line 19, add
x
, y
coordinate of create_image
.
Here is re-wrote for ttk
:
from tkinter import ttk
import tkinter as tk
win= tk.Tk()
win.geometry("300x550+970+45")
win.title("Gui")
style = ttk.Style()
style.configure("Font.TButton", font=('Arial','21'))
l = tk.Label(win, text="Save File").pack()
btn = ttk.Button(text="Save", style="Font.TButton") #<== add style
btn.pack(pady=10)
f = ttk.Frame(win,width=200,height=200).place(x=50,y=275)
f_canvas = tk.Canvas(f,background='red',width=200,height=200)
img = tk.PhotoImage(file='p1.png') #<== add image
f_canvas.create_image(0, 10, image=img,anchor=tk.NW) #<== x, y coordinate
f_canvas.place(x=50,y=275)
win.mainloop()
Screenshot for ttk
font and image:
