首页 > 解决方案 > 具有透明背景 Python 的 Tkinter 图像按钮

问题描述

我对 python 真的很陌生,并试图让一个触摸 gui 与 python 一起运行。

我在 figma 中设计了它,现在我要让按钮运行了。

问题是,我不会得到按钮的透明背景。有没有其他方法可以代替 tkinter?

我最后一次尝试是使用鼠标点击的坐标,只使用图标作为背景。但是如果没有为背景制作许多新图像,我就不会得到这个“点击”动画。

此代码独立运行并显示我的问题:

from tkinter import *
from tkinter.ttk import *
from PIL import Image, ImageTk
import tkinter as tk

window = Tk()
window.title('title')
window.geometry('1024x768')

Background = PhotoImage(file="Background.gif")
Background_Label = Label(window, image = Background)
Background_Label.place(x = 0, y = 0, relwidth = 1, relheight = 1)

ButtonMapLoad = Image.open('ButtonMap.png')
ButtonMap = ImageTk.PhotoImage(ButtonMapLoad)
tk.Button(window, image=ButtonMap, borderwidth = 0 , highlightthickness = 0, relief = "flat", overrelief = "flat").pack(padx = 100, pady = 20)


mainloop()

图片显示了我的按钮的外观。

背景按钮:

图片

我只想要一个看起来不像 1998 年的漂亮 GUI :-(

在此先感谢,祝您有美好的一天。

威廉

标签: pythontkinterbuttonbackground

解决方案


推荐阅读