这是我要摆脱白色物质的图像
我将努力使这篇文章比上一篇更好。我唯一的问题是,我编写的代码会生成一个以背景为图像的屏幕。我要做的是使按钮成为文本图像。但是,当我使按钮成为图像时,文本周围没有空格填充文本框。我已确保删除图像的任何背景。我想知道是否有一种方法可以消除白色碎片。非常感谢。
import tkinter as tk
from tkinter import *
from tkinter import messagebox
class HoverButton(tk.Button):
def __init__(self, master, **kw):
tk.Button.__init__(self,master=master,**kw)
self.defaultBackground = self["background"]
self.bind("<Enter>", self.on_enter)
self.bind("<Leave>", self.on_leave)
def on_enter(self, e):
self['background'] = self['activebackground']
def on_leave(self, e):
self['background'] = self.defaultBackground
def main_screen():
global main
main = Tk()
main.title("Home")
main.geometry("800x600")
filename = PhotoImage(file = "C:\\Users\\frase\Documents\\bg.png")
bg_label = Label(main, image=filename)
bg_label.place(x=0, y=0, relwidth=1, relheight=1)
playfile = tk.PhotoImage(file = "C:\\Users\\frase\Documents\\button.png")
b = Button(main, text="Play", image = playfile, highlightthickness=0, bd=0)
b.pack()
main.mainloop()
main_screen()