"Steven D'Aprano" <steve+comp.lang.pyt...@pearwood.info> a écrit dans le message de news:54898820$0$12989$c3e8da3$54964...@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_()
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to