[tkinter] trouble running imported modules in main program

snakeinmyboot mikelhamer at gmail.com
Wed Aug 7 00:25:05 EDT 2013


On Tuesday, August 6, 2013 7:38:55 PM UTC-4, Terry Reedy wrote:
> On 8/6/2013 6:28 PM, snakeinmyboot wrote:
> 
> > Hello,
> 
> >
> 
> > I am currently just starting to learn the basics of the tkinter module and ive run into a problem. To teach myself I am messing around by creating separate modules containing basic GUI apps like a tip calculator and kilometer converter, then creating a main program that displays buttons you can click that will create instances of the modules (tip calculator, kilometer converter). So far ive managed to successfully make the basic GUI apps works just fine, and have been able to import them into my main program and get them to launch in a new window when i click the buttons and everything, but heres my problem.
> 
> >
> 
> > Everything displays ok, like the labels, entry boxes, and buttons, but when I actually click the buttons (which are supposed to trigger a method within the module and display a label containing the calculated data).. nothing happens. When I run the modules by themselves everything works just fine (testing by making the module create an instance of itself but i # them out before running the main program)
> 
> 
> 
> Make the boilerplate test code conditional, something like
> 
> 
> 
> if __name__ == '__main__':
> 
>      root = tkinter.Tk()
> 
>      app = MainClass(root)  # 'MainClass' depends on the module.
> 
>      root.mainloop
> 
>      root.destroy
> 
> 
> 


Could you elaborate on this a little bit? Never even heard the term "boilerplate test code".
Also, I have removed the mainloops from the other modules, but this didnt seem to affect anything.
 Thanks for the reply!



More information about the Python-list mailing list