简体   繁体   English

如何删除 Tkinter OptionMenu 小部件的边框

[英]How to remove the border of a Tkinter OptionMenu Widget

I have been looking through multiple websites, which only give me a half satisfactory answer, how would I colour each part of of a Tkinter OptionMenu Widget?我浏览了多个网站,只给了我一半满意的答案,我将如何为 Tkinter OptionMenu Widget 的每个部分着色?

Code Snippet:代码片段:

from tkinter import *

root = Tk()
text = StringVar()

fr = Frame (root,bg="yellow")
fr.grid()

menu = OptionMenu (fr, text, "hi", "there")
menu.grid (pady=50, padx=50)

# Pretty colouring goes here
# Or ugly yellow, I don't mind

menu ["menu"] ["bg"] = "yellow"
menu ["bg"] = "yellow"
menu ["activebackground"] = "green"

root.mainloop()

Or should I just give up and settle for grey?还是我应该放弃并满足于灰色?

All that I had to do was set the highlightthickness option to 0我所要做的就是将highlightthickness选项设置为0

menu["highlightthickness"]=0

This get's rid of the ugly border around the drop down menu.这摆脱了下拉菜单周围的丑陋边框。

要摆脱边框,请使用选项:menu["borderwidth"] = 0。

I don't understand your problem.我不明白你的问题。

menu["menu"] is a tkinter.Menu object, so you can set others options. menu["menu"] 是一个 tkinter.Menu 对象,因此您可以设置其他选项。

Possible colors options are :可能的颜色选项是:

  • activebackground -> that you want activebackground -> 你想要的
  • activeforeground -> that you want activeforeground -> 你想要的
  • background背景
  • bg背景
  • disabledforeground禁用前景
  • fg fg
  • foreground前景
  • selectcolor选择颜色

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM