填充菜单按钮

时间:2019-06-24 04:42:02

标签: python tkinter

我正在制作一个tkinter gui应用程序,我需要菜单。但是我不知道如何在一个python文件中将小部件添加到menubutton中(我需要填充它),我一直不得不制作多个python文件。我该怎么办?

我尝试将'gui'更改为'Password_List',但它一直显示在第一页上。我的代码:

from tkinter import *
import os
from pathlib import Path

def writeFile():
    file = open('data/ProPassList.txt'+" ", 'a+')
    file.write("~" + metinF.get() + '\n')
    file.write("\n")
    file.close()


gui = Tk()
gui.geometry("900x500")
gui.title("Pro Pass")
gui.iconbitmap('data/icon.ico')

filename = PhotoImage(file='data/bg.png')
background_label = Label(image=filename)
background_label.place(relwidth=1, relheight=1)

mb = Menubutton(gui, text="Menu", bg="#000332", font="Impact", foreground="white")
mb.Menu = Menu(mb)
mb["menu"] = mb.Menu


Home = mb.Menu.add_command(label="Home")
mb.pack(ipadx="36", ipady="10", anchor="w", side="top")

PPLexist = Path('data/ProPassList.txt')

def openfile():
    if PPLexist.is_file():
        gui.destroy()
        os.system('python ProPassList.py')
    else:
        ErrorPop = Toplevel(bg='black')
        ErrorPop.geometry('250x50')
        ErrorPop.title('Error!')
        ErrorPop.iconbitmap('data/icon.ico')
        ErrorPopLabel = Label(ErrorPop, text="You Haven't Stored A Password Yet!", font=('Arial', 10, 'bold'), bg='black', fg='white')
        ErrorPopLabel.pack(pady=10)


Password_List = mb.Menu.add_command(label="Password List", command=openfile)
mb.pack(ipadx="36", ipady="10", anchor="w", side="top")

quits = mb.Menu.add_command(label="Exit", command=lambda: quit())
mb.pack(ipadx="36", ipady="10", anchor="w", side="top")

frame = Frame(gui, bg="#710cd9")
frame.place(x=330, y=200)

label = Label(frame, text="Store Your Password", bg="#710cd9", font="Tahoma")
label.pack()

metinF = Entry(frame, show="*", bd=2, bg="#000108", fg="white")
metinF.place(relwidth=5)
metinF.pack(ipadx=10, ipady=3)


buttonWrite = Button(frame, bg="#00f0ff")
buttonWrite.config(text='Save', command=writeFile)
buttonWrite.place(y=1)
buttonWrite.pack(ipady=5, ipadx=30)

gui.mainloop()

我希望单击并在菜单按钮中显示另一个GUI框架

(我在Windows 10、64x系统,Python 3.7上)

0 个答案:

没有答案