[英]Tkinter i want to add a background image and want to display widgets on top of that , but widgets hiding behind the image
弧隐藏在图像后面,我想将其显示在图像上方以及如何添加更多覆盖在背景图像上的图像
from itertools import cycle
from random import randrange
from tkinter import Tk , Canvas , messagebox , font
from tkinter import *
from tkinter.ttk import *
canvasw = 1200
canvash = 800
win = Tk()
c = Canvas(win, bg="blue", height=canvash, width=canvasw)
backg = PhotoImage(file = "back.png")
background_label = Label(win, image=backg)
background_label.place(x=0, y=0, relwidth=1, relheight=1)
eg = PhotoImage(file = "eg.png")
ep = PhotoImage(file = "ep.png")
er = PhotoImage(file = "er.png")
ey = PhotoImage(file = "ey.png")
ew = 45
eh = 55
es = 10
ev = 500
ei = 4000
dfcl = 0.95
catchcol = 'black'
catw = 100
cath = 100
catsx1 = canvasw / 2 - catw /2
catsy1 = canvash - cath -20
catsx2 = catsx1 + catw
catsy2 = catsy1 + cath
cat = c.create_arc(catsx1,catsy1,catsx2,catsy2, start= 200 ,extent = 140, style='arc', outline=catchcol, width=3)
c.pack()
win.mainloop()
弧隐藏在图像后面,我想将其显示在图像上方
relwidth=1, relheight=1
导致弧线不显示
也一样
background_label.place(x=0, y=0)
relwidth=1, relheight=1
将 label 设置为与 window 一样大,因此 label 将涵盖所有内容。
您应该使用create_image()
将背景图像放入 canvas 而不是使用 label:
c.create_image(0, 0, image=backg, anchor='nw')
请注意,您应该避免导入以下模块:
from tkinter import Tk , Canvas , messagebox , font
from tkinter import *
from tkinter.ttk import *
第一个导入被第二个导入覆盖,因此第一个导入不是必需的。 此外, tkinter
中的一些小部件将被第三次导入覆盖,即来自ttk
的小部件。
您应该按如下方式导入模块:
import tkinter as tk
from tkinter import ttk
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.