基本上,我正在创建一个待办事项列表,该任务列表在单击时在侧面具有一系列Notebook选项卡,在右侧显示ScrolledText窗口。这是“待办事项清单”的图片。 Here is the image link. 但是,我想要的是在“滚动文本”顶部有一个菜单。主窗口称为root,使用Notebook Widget分隔。单击选项卡时,包含滚动文本的区域是一个单独的框架,称为Task1,我希望菜单栏位于其上方。 Task1没有到达窗口的顶部,它是主窗口的右侧部分,不包括顶部的灰色条。我希望菜单栏位于Task1的顶部,而不是主窗口的顶部。这是我的代码:
from tkinter import *
import datetime
from tkinter import ttk
from tkinter.scrolledtext import ScrolledText
import tkinter as tk
from tkinter import Menu, filedialog
root = Tk()
class ToDoList(tk.Frame):
def __init__(self, master):
root.columnconfigure(2, weight=1)
root.rowconfigure(1, weight=1)
root.title("To - Do List")
root.geometry("1200x600")
root.configure(background = "white")
# Variable list:
style = ttk.Style()
current_theme =style.theme_use()
style.theme_settings(current_theme, {"TNotebook.Tab": {"configure": {"padding": [20, 5], "background" : "white"}}})
style.theme_settings(current_theme, {"TNotebook" : {"configure" : {"tabposition" : "wn", "padding" : (0, 5)}}})
style.theme_settings(current_theme, {"TNotebook.Window" : {"configure" : {"width" : 500}}})
TasksList = ttk.Notebook(root)
Task1 = tk.Frame(TasksList, bg='white', height = 1000, width = 2000)
text=ScrolledText(Task1, width = 132, height = 120)
text.grid(row = 2, column = 0)
entry1 = Entry(Task1, width = 179)
entry1.grid(row=0, column=0, sticky = W)
Task2 = tk.Frame(TasksList, bg='white')
text=ScrolledText(Task2, width = 132, height = 120)
text.grid(row = 0, column = 0)
entry2 = Entry(Task1, width = 179)
entry2.grid(row=0, column=0, sticky = W)
Task3 = tk.Frame(TasksList, bg = "white")
text=ScrolledText(Task3, width = 132, height = 120)
text.grid(row = 0, column = 0)
entry3 = Entry(Task1, width = 179)
entry3.grid(row=0, column=0, sticky = W)
TasksList.add(Task1,text = 'Click Here In Order To Read The Instructions')
TasksList.add(Task2, text = 'Two Two Two Two Two Two'[0: 40] + '...')
TasksList.add(Task3, text = "Three Three Three Three Three Three Three Extra"[0 : 40] + '...')
TasksList.grid(row=1, column=0, sticky=N+W, columnspan=3)
Photo2 = PhotoImage(file="Add Task Image Button.png")
Button(root, image=Photo2, borderwidth=0, highlightthickness=0).grid(row=0, column=1, sticky=E)
Photo1= PhotoImage(file="Final Logo.png")
Label(image=Photo1, bg="black", borderwidth=0, highlightthickness=0).grid(row=0, column=0, sticky=W)
我包括了很多代码,以便更轻松地查看“任务清单”的组织。我希望有办法做到这一点,如果有人可以提供帮助,我将不胜感激。谢谢!
答案 0 :(得分:0)
您可以将菜单按钮添加到框架并创建附加到它们的菜单。请参见以下示例:
from tkinter import *
root = Tk()
root.geometry('300x200+800+50')
top = Frame(root, bg='tan')
top.pack(expand='yes', fill='both', padx=20, pady=20)
mb = Menubutton(top, text="condiments", relief=RAISED)
mb.pack(anchor='nw')
mb.menu = Menu(mb, tearoff=0)
mb["menu"] = mb.menu
def hello(): print('Hello')
mb.menu.add_checkbutton ( label="ketchup" )
mb.menu.add_command(label="Hello!", command=hello)
root.mainloop()