在Python中添加一个菜单栏到我的cod时出现了一个TkInter bug

2024-07-08 08:51:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我在TkInter中找到了一些创建菜单栏的代码,但是如果没有它的bug,我就无法放入我的代码。你知道吗

下面是我使用的代码:

from Tkinter import *
import subprocess
import os
master = Tk()
master.geometry("1000x668")
master.title("Menu")
master.configure(background='pale green')
master.iconbitmap(r"C:\Users\André\Desktop\python\menu.ico")
master = Tk()

def NewFile():
    print "New File!"
def OpenFile():
    name = askopenfilename()
    print name
def About():
    print "This is a simple example of a menu"
menu = Menu(master)
master.config(menu=menu)
filemenu = Menu(menu)
menu.add_cascade(label="File", menu=filemenu)
filemenu.add_command(label="New", command=NewFile)
filemenu.add_command(label="Open...", command=OpenFile)
filemenu.add_separator()
filemenu.add_command(label="Exit", command=master.quit)

w = Label(master, text="Abrir", bg="pale green", fg="steel blue", font=("Algerian", 20, "bold"))
w.pack()
w.place(x=100, y=0)
def notepad():
    subprocess.Popen("notepad.exe")
buttonote = Button(master, text="Bloco de notas", wraplength=50, justify=CENTER, padx=2, bg="light sea green", height=2, width=7, command=notepad)
buttonote.pack()
buttonote.place(x=0, y=50)
def regedit():
    subprocess.Popen("regedit.exe")
buttonreg = Button(master, text="Editor de Registo", wraplength=50, justify=CENTER, padx=2, bg="light sea green", height=2, width=7, command=regedit)
buttonreg.pack()
buttonreg.place(x=60, y=50)
def skype():
    subprocess.Popen("skype.exe")
buttonskype = Button(master, text="Skype", bg="light sea green", height=2, width=7, command=skype)
buttonskype.pack()
buttonskype.place(x=120, y=50)
def steam():
    os.startfile("D:\Steam\Steam.exe")
buttonsteam = Button(master, text="Steam", bg="light sea green", height=2, width=7, command=steam)
buttonsteam.pack()
buttonsteam.place(x=178, y=50)
e1 = Entry(master, width=15)
e1.pack(padx=100,pady=4, ipadx=2)
def save():
    text = e1.get()
    SaveFile = open('information.txt','w')
    SaveFile.write(text)
    SaveFile.close()
nome = Label(master, text="Nome?", bg="pale green", fg="steel blue", font=("Arial Black", 12))
nome.pack()
nome.place(x=380, y=0)
buttonsave = Button(master, text="Guardar", bg="light sea green", height=1, width=6, command=save)
buttonsave.pack()
buttonsave.place(x=550, y=0)

f = open('information.txt','r')
line = f.readline()
show = Label(master, text=line, bg="pale green", fg="steel blue", font=("Arial Black", 12))
show.pack()
show.place(x=32, y=640)
hi = Label(master, text='Hi, ', bg="pale green", fg="steel blue", font=("Arial Black", 12))
hi.pack()
hi.place(x=0, y=640)
master.mainloop()

有人能找出我的代码有什么问题吗?谢谢!你知道吗


Tags: textmasteradddefplacebuttongreenwidth

热门问题