我一直在使用pythonprograming.net中的代码,这是指向该页面的链接。 https://pythonprogramming.net/creating-main-menu-tkinter/
我正在尝试创建一个列表框,当您单击菜单栏中的按钮时会显示该列表框。我有一个基本列表框的代码,我从这里得到。 Display Listbox with columns using Tkinter?
我的问题是如何使用从第二个链接找到的通用代码填充我的列表框?
到目前为止,这是我的代码:
def popupmsg(msg):
popup = tk.Tk()
popup.wm_title("Save Settings")
label = ttk.Label(popup, text=msg, font=NORM_FONT)
label.pack(side="top", fill="x", pady=10)
B1 = ttk.Button(popup, text="Okay", command = popup.destroy)
B1.pack()
def ParameterSelectionmsg(Treeview):
popup = tk.Tk()
popup.wm_title("Parameter Selection")
label = ttk.Listbox(popup, text=msg, font=NORM_FONT)
label.pack(side="top", fill="x", pady=10)
B1 = ttk.Button(popup, text="Okay", command = popup.destroy)
B1.pack()
popup.mainloop()
popup.mainloop()
我想使用treeview在此ParameterSelection弹出菜单中构建列表框。
class MyTkinter(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
#tk.Tk.iconbitmap(self, default="clienticon.ico")
tk.Tk.wm_title(self, "My Tkinter")
container = tk.Frame(self)
container.pack(side="top", fill="both", expand = True)
container.grid_rowconfigure(0, weight=1)
container.grid_columnconfigure(0, weight=1)
menubar = tk.Menu(container)
filemenu = tk.Menu(menubar, tearoff=0)
filemenu.add_command(label="Save settings", command = lambda: popupmsg("IDK how to do this!"))
filemenu.add_command(label="New", command = lambda: popupmsg("IDK how to do this!"))
filemenu.add_command(label="Add", command = lambda: popupmsg("Add Parameter"))
filemenu.add_command(label="Exit", command=quit)
menubar.add_cascade(label="File", menu=filemenu)
tk.Tk.config(self, menu=menubar)
editmenu = tk.Menu(menubar, tearoff=1)
editmenu.add_command(label="Save settings", command = lambda: popupmsg("IDK how to do this!"))
editmenu.add_command(label="New", command = lambda: popupmsg("IDK how to do this!"))
editmenu.add_command(label="Add", command = lambda: popupmsg("Add Parameter"))
editmenu.add_command(label="Exit", command=quit)
menubar.add_cascade(label="Edit", menu=editmenu)
tk.Tk.config(self, menu=menubar)
parameter = tk.Menu(menubar, tearoff=1)
parameter.add_command(label="Selection", command = lambda: popupmsg("This should contain the list of parameters"))
menubar.add_cascade(label="Parameter", menu=parameter)
tk.Tk.config(self, menu=menubar)
self.frames = {}
for F in (StartPage, PageOne):
frame = F(container, self)
self.frames[F] = frame
frame.grid(row=0, column=0, sticky="nsew")
self.show_frame(StartPage)
def show_frame(self, cont):
frame = self.frames[cont]
frame.tkraise()
class StartPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self,parent)
label = tk.Label(self, text="Start Page", font=LARGE_FONT)
label.pack(pady=10,padx=10)
button1 = ttk.Button(self, text="Graph Page",
command=lambda: controller.show_frame(PageOne))
button1.pack()
class PageOne(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
label = tk.Label(self, text="Graph Page!", font=LARGE_FONT)
label.pack(pady=10,padx=10)
button1 = ttk.Button(self, text="Back to Home",
command=lambda: controller.show_frame(StartPage))
button1.pack()
#Graph Code
plt.style.use("dark_background")
x = (g[0].time[:111358])
y = (g[0].data.f[:111358])
df = pd.DataFrame({'Time': x, 'Data': y})
fig = plt.figure()
plt.plot(x, y)
plt.title('ParmName', fontsize = 15)
plt.xlabel('Time', fontsize=12)
plt.ylabel('Data', fontsize=12)
plt.grid(linestyle = 'dashed')
canvas = FigureCanvasTkAgg(fig, self)
canvas.show()
canvas.get_tk_widget().pack(side=tk.BOTTOM, fill=tk.BOTH, expand=True)
toolbar = NavigationToolbar2TkAgg(canvas, self)
toolbar.update()
canvas._tkcanvas.pack(side=tk.TOP, fill=tk.BOTH, expand=True)
app = MyTkinter()
app.mainloop()