我一直在尝试使用我在另一个函数中定义的变量,但我不想使用全局变量。
import sys
from tkinter import *
from tkinter import messagebox
from tkinter import colorchooser
from tkinter import filedialog
x = "#000000"
#colour chooser
def mColour():
color = colorchooser.askcolor()
mlabel2 = Label(mGui,text=color).pack()
messagebox.showinfo(title = "Colour",message = "This feature has not been fully added yet.")
x = color[1]
print (color[1])
return x
#printing message
def mhello():
mtext = ment.get()
mlabel2 = Label(mGui,text=mtext, fg = (b)) # color varible = x
mlabel2.pack()
#message
def mNew():
messagebox.showerror(title = "(New) Error",message = "This feature has not been added yet.")
def mAbout():
messagebox.showinfo(title = "About",message = "This Jono's susure personal data base. (Will be)")
#question message
def mQuit():
mExit = messagebox.askokcancel(title = "Quit",message = "Are you sure")
if mExit > 0:
mGui.destroy()
#open
def mOpen():
myopen = filedialog.askopenfile()
mlabel3 = Label(mGui,text=myopen).pack()
messagebox.showinfo(title = "Open",message = "This feature has not been fully added yet.")
mGui = Tk()
ment = StringVar()
mGui.geometry("300x200+100+100")
mGui.title("Jono's Clock")
mlable = Label(mGui,text="My Label",fg = "red").pack()
mbutton = Button(mGui,text ="OK",command = mhello,fg = "red").pack()
mEntry = Entry(mGui,textvariable=ment).pack()
# Menu
menubar = Menu(mGui)
filemenu = Menu(menubar, tearoff = 0)
filemenu.add_command(label = "New",command = mNew)
filemenu.add_command(label = "Open",command = mOpen)
filemenu.add_command(label = "Colour",command = mColour)
filemenu.add_command(label = "About",command = mAbout)
filemenu.add_command(label = "Quit",command = mQuit)
menubar.add_cascade(label = "File",menu = filemenu)
mGui.config(menu = menubar)
mGui.mainloop()
我在 Windows 7 上使用 python 3.3。
我已按要求添加了其余代码。