Har*_*onT 0 python tkinter tkinter-label tkinter-button
我知道如何删除 Tkinter 按钮和图像的边框。它的完成方式与其他所有事情的完成方式几乎完全相同
borderwidth=0
Run Code Online (Sandbox Code Playgroud)
我需要帮助,如果为什么,即使我将其放入小部件的“设计参数”中,它仍然有边框。
我的代码如下。
# Imports the tkinter library.
from tkinter import *
from tkmacosx import Button
selectedBackground = "black"
selectedForeground = "#22fd35"
root = Tk()
root.configure(bg=selectedBackground)
def openCipher():
print("open cipher")
def openDecipher():
print("open decipher")
cipherButton = Button(root, text=" Cipher ", padx=40, pady=20, command=openCipher, borderwidth=0, background=selectedBackground, foreground=selectedForeground, highlightbackground=selectedForeground)
cipherButton.grid(row=1, column=0)
decipherButton = Button(root, text="Decipher", padx=40, pady=20, command=openDecipher, borderwidth=0, background=selectedBackground, foreground=selectedForeground, highlightbackground=selectedForeground).grid(row=1, column=2)
spacer1 = Label(root, text=" ", padx=10, pady=1, background=selectedBackground, foreground=selectedForeground, highlightbackground=selectedForeground).grid(row=4, column=1)
quitButton = Button(root, text="Exit d3cryptt", padx=10, pady=5, command=root.quit, borderwidth=0, background=selectedBackground, foreground=selectedForeground, highlightbackground=selectedForeground).grid(row=5, column=1)
spacer2 = Label(root, text=" ", padx=10, pady=1, background=selectedBackground, foreground=selectedForeground, highlightbackground=selectedForeground).grid(row=6, column=1, pady=30)
# changecolour = Button(root, text="change colour", padx=1, pady=5, background=selectedBackground, foreground=selectedForeground, highlightbackground=selectedForeground, command=lambda: changeColour(selectedBackground3, selectedForeground3)).grid(row=7, column=0)
theme1 = PhotoImage(file = "/Documents/theme1button.png")
theme1Button = Button(root, image=theme1, borderwidth=0, background=selectedBackground, command=openCipher)
theme1Button.place(x=50, y=100)
#Enter the event main loop
root.mainloop()
Run Code Online (Sandbox Code Playgroud)
如果您想自己测试一下,这里是按钮的图像。 https://i.stack.imgur.com/OzB58.png
即使 borderwidth = 0,图像也会出现在屏幕上,周围有边框,如下图所示。
我不确定是否有任何其他解决方案可以解决此问题。我什至尝试将其从 .place 更改为 .grid,但它仍然有边框。
可能是因为它不在画布上,但我需要有人为我澄清这是否是问题所在。如果他们可以指导我如何做到这一点,或者提供有关如何做到这一点的有用视频,我将不胜感激。
我很感激给出的任何建议。
小智 5
尝试突出显示厚度:
theme1Button = Button(root, image=theme1, borderwidth=0, highlightthickness=0, background=selectedBackground, command=openCipher)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
704 次 |
| 最近记录: |