Problem with a dialog
ast
nomail at invalid.com
Thu Dec 11 07:59:12 EST 2014
"Steven D'Aprano" <steve+comp.lang.python at pearwood.info> a écrit dans le message de
news:54898820$0$12989$c3e8da3$5496439d at news.astraweb.com...
> You can make "test" global by declaring it global:
>
> def try_():
> global test
> test = True
> setup = MyDialog(root)
>
>
>
> If that solves your problem to your satisfaction, you can stop reading now.
>
Since try() is a callback function called when a button is pushed,
with the effect to open a dialog, I tried to define MyDialog class
inside try(). The program is the following and it works. I no
longer need to define test as global.
Is it a good practice to define a class inside a function ?
from tkinter import *
import tkinter.simpledialog
def try_():
class MyDialog(tkinter.simpledialog.Dialog):
def body(self, master):
print(test)
def apply(self):
pass
test = True
setup = MyDialog(root)
root = Tk()
try_()
More information about the Python-list
mailing list