我怎样才能让我的任务栏永远在最前面?
How can i put my taskbar to be always on top?
我想将我的菜单栏框架放在 window 的顶部,就像 tkinter 的菜单模块一样。
class My_Menu:
def __init__(self, master, name="Default", expand="full", mode="bar"):
##### create the frame #####
self.menus = {}
self.master = master
self.master.columnconfigure(0, weight=1)
self.master.rowconfigure(0, weight=0)
self.master_frame = Frame(self.master)
self.master_frame.grid(row=0, column=0, sticky=NSEW)
self.master_frame.columnconfigure(0, weight=1)
self.master_frame.rowconfigure(0, weight=1)
self.main_frame = Frame(self.master_frame)
self.main_frame.grid(row=0, column=0, sticky=NSEW)
self.main_frame.rowconfigure(0, weight=0)
我不确定是否有任何方法可以做到这一点,但解决方法是在该行中创建 space 并使用 sticky
始终将菜单置于顶部。
from tkinter import *
class MenuFrame(Frame):
def __init__(self,parent,*args,**kwargs):
Frame.__init__(self,parent,*args,**kwargs)
self.b1 = Button(self,text='File',width=50)
self.b1.grid(row=0,column=0)
self.b2 = Button(self,text='Help',width=50)
self.b2.grid(row=0,column=1)
def ret_max(self):
self.update()
return self.b1.winfo_height()
root = Tk()
menu = MenuFrame(root)
menu.grid(row=0,column=0,sticky='n') # Can move this line in or out of class
height = menu.ret_max()
root.grid_rowconfigure(0,pad=height) # Make it have extra space of height of button
Button(root,text='Dummy Button').grid(row=0,column=0,sticky='s')
root.mainloop()
我想将我的菜单栏框架放在 window 的顶部,就像 tkinter 的菜单模块一样。
class My_Menu:
def __init__(self, master, name="Default", expand="full", mode="bar"):
##### create the frame #####
self.menus = {}
self.master = master
self.master.columnconfigure(0, weight=1)
self.master.rowconfigure(0, weight=0)
self.master_frame = Frame(self.master)
self.master_frame.grid(row=0, column=0, sticky=NSEW)
self.master_frame.columnconfigure(0, weight=1)
self.master_frame.rowconfigure(0, weight=1)
self.main_frame = Frame(self.master_frame)
self.main_frame.grid(row=0, column=0, sticky=NSEW)
self.main_frame.rowconfigure(0, weight=0)
我不确定是否有任何方法可以做到这一点,但解决方法是在该行中创建 space 并使用 sticky
始终将菜单置于顶部。
from tkinter import *
class MenuFrame(Frame):
def __init__(self,parent,*args,**kwargs):
Frame.__init__(self,parent,*args,**kwargs)
self.b1 = Button(self,text='File',width=50)
self.b1.grid(row=0,column=0)
self.b2 = Button(self,text='Help',width=50)
self.b2.grid(row=0,column=1)
def ret_max(self):
self.update()
return self.b1.winfo_height()
root = Tk()
menu = MenuFrame(root)
menu.grid(row=0,column=0,sticky='n') # Can move this line in or out of class
height = menu.ret_max()
root.grid_rowconfigure(0,pad=height) # Make it have extra space of height of button
Button(root,text='Dummy Button').grid(row=0,column=0,sticky='s')
root.mainloop()