2024-04-20 13:44:00 发布
网友
我正在用python创建一个简单的gui应用程序。我知道tkinter中现有的下拉菜单选项,但我希望它出现在标题栏上。类似于在ubuntu18.04中的gnome计算器(在模式之间选择)。如何使用python3tkinter实现这一点?你知道吗
您需要使用self.overrideredirect(True)创建一个无框架窗口,并在窗口顶部放置一个表示标题栏的小部件。把你的下拉列表放到那个小部件里。简单示例:
self.overrideredirect(True)
import tkinter from tkinter import ttk class App(tkinter.Tk): def __init__(self): tkinter.Tk.__init__(self) self.title("Example") self.overrideredirect(True) self.title_bar = ttk.Combobox(values=["Mode 1", "Mode 2"]) self.title_bar.set("Mode 1") self.title_bar.state(["readonly"]) self.title_bar.pack() app = App() app.mainloop()
请注意,在本例中,窗口在任务栏中不可见。见Tkinter, Windows: How to view window in windows task bar which has no title bar?
您需要使用
self.overrideredirect(True)
创建一个无框架窗口,并在窗口顶部放置一个表示标题栏的小部件。把你的下拉列表放到那个小部件里。简单示例:请注意,在本例中,窗口在任务栏中不可见。见Tkinter, Windows: How to view window in windows task bar which has no title bar?
相关问题 更多 >
编程相关推荐