我要做的是在顶部放置导航栏的应用程序,具体取决于哪个显示在应用程序主体上(导航条下方)。我正在使用网格,因此要遍历列表并向应用程序主体中添加一个按钮,它们具有columnpan,但它们位于columnpan的中间
这就是现在的样子。
这是布局的草图(导航栏下方的右栏是一个滚动条,由于我尚不知道如何实现,所以该滚动条尚未实现)
import modules.configManager as configManager
import tkinter as tk
from tkinter import messagebox
import tkinter.font as font
from os.path import dirname, abspath
from PIL import Image, ImageTk
imgDirectory = dirname(dirname(abspath(__file__))) + '\img'
logo = imgDirectory + '\logo2.jpg'
root = tk.Tk()
def linkMenu():
links = configManager.readConfig()['linksList']
i = 0
for link in links:
i = i+1
linkB = tk.Button(root,text=link['link'],font=font.Font(font='Helvetica',size=8),width=30,relief='flat')
linkB.grid(column=0,row=i,columnspan=4)
def navbar():
buttonWidth = 18
buttonHeight = 1
myfont = font.Font(font='Helvetica',size=10,weight="bold")
homeButton = tk.Button(root, text="Home",height=buttonHeight,width=buttonWidth,font=myfont)
homeButton.grid(column=0,row=0)
linkButton = tk.Button(root, text="Links",width=buttonWidth,font=myfont,command=linkMenu)
linkButton.grid(column=1,row=0)
groupsButton = tk.Button(root, text="Groups",width=buttonWidth,font=myfont)
groupsButton.grid(column=2,row=0)
resetButton = tk.Button(root, text="Reset",width=buttonWidth,font=myfont)
resetButton.grid(column=3,row=0)
exitButton = tk.Button(root,text="Exit",width=buttonWidth,font=myfont,command=exit)
exitButton.grid(column=4,row=0)
def interface():
navbar()
root.title("LinkManager")
root.geometry("1040x500")
root.mainloop()
提前谢谢,如果不清楚,请告诉我:D