関数内で定義した変数を別の関数内で使用しようとしましたが、グローバルを使用したくありません。
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を使用しています。
リクエストに応じて残りのコードを追加しました。