Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 如何在不在窗口顶部的框架顶部创建菜单_Python 3.x_Tkinter_Menu - Fatal编程技术网

Python 3.x 如何在不在窗口顶部的框架顶部创建菜单

Python 3.x 如何在不在窗口顶部的框架顶部创建菜单,python-3.x,tkinter,menu,Python 3.x,Tkinter,Menu,基本上,我正在创建一个待办事项列表,该列表侧面有一系列笔记本选项卡,单击后,在右侧显示一个滚动文本窗口。这是一张待办事项清单的图片。 然而,我想要的是在滚动文本的顶部有一个菜单。名为root的主窗口使用Notebook小部件进行分隔。单击选项卡时,包含滚动文本的区域是一个单独的框架,称为Task1,我希望菜单栏位于其顶部。Task1未到达窗口顶部,它是主窗口的右侧部分,不包括顶部的灰色条。我希望菜单栏位于Task1的顶部,而不是主窗口的顶部。这是我的密码: from tkinter import

基本上,我正在创建一个待办事项列表,该列表侧面有一系列笔记本选项卡,单击后,在右侧显示一个滚动文本窗口。这是一张待办事项清单的图片。 然而,我想要的是在滚动文本的顶部有一个菜单。名为root的主窗口使用Notebook小部件进行分隔。单击选项卡时,包含滚动文本的区域是一个单独的框架,称为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)

我已经包含了很多代码,以便更容易看到待办事项列表的组织。我希望有办法做到这一点,如果有人能帮忙,我将不胜感激。谢谢大家!

您可以将菜单按钮添加到框架中,并创建附加到它们的菜单。请参见此示例:

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()
改编自