【发布时间】:2022-11-26 13:35:37
【问题描述】:
我知道如何删除 Tkinter 按钮和图像的边框。它的完成方式与您为其他所有事情所做的方式几乎完全一样
borderwidth=0
为什么我需要帮助,即使我把它放在小部件的“设计参数”中,它仍然有一个边框。
我的代码如下。
# 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()
如果您想自己测试一下,这是按钮的图像。 https://i.stack.imgur.com/OzB58.png
图像出现在屏幕上时周围有边框,即使 borderwidth = 0,如下图所示。
我不确定关于如何解决此问题的任何其他解决方案。我什至尝试将其从 .place 更改为 .grid,但它仍然有边框。
可能是因为它不在画布上,但如果这是问题所在,我需要有人为我澄清。如果他们能指导我如何操作,或者提供有关如何操作的有用视频,我将不胜感激。
我很感激给出的任何建议。
【问题讨论】:
-
如果您只放置没有按钮的图像会怎样?
-
@AnthonyL 没有边界。
-
它看起来就像从填充或边距向我显示的背景。不过我确实放大了它们,那些是一些粗的 0 宽度边框
标签: python tkinter tkinter-button tkinter-label