Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:: [': 0.04; 'beginner': 0.05; 'root': 0.05; 'ignored': 0.07; 'tkinter': 0.07; '__name__': 0.09; 'buttons': 0.09; 'happens.': 0.09; 'here?': 0.09; 'messing': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:modules': 0.09; 'gui': 0.12; 'jan': 0.12; 'posted': 0.15; "'__main__':": 0.16; 'buttons,': 0.16; 'calculator': 0.16; 'comments:': 0.16; 'imported.': 0.16; 'labels,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'spacing': 0.16; 'subject:program': 0.16; 'unneeded': 0.16; 'apps': 0.16; 'wrote:': 0.18; 'app': 0.19; 'module': 0.19; 'subject:] ': 0.20; 'command': 0.22; 'import': 0.22; 'separate': 0.22; 'creating': 0.23; 'header :User-Agent:1': 0.23; 'fine': 0.24; 'right.': 0.26; 'suggested': 0.26; 'read,': 0.26; 'header:X-Complaints-To:1': 0.27; 'header:In- Reply-To:1': 0.27; 'idea': 0.28; 'leave': 0.29; 'label': 0.30; '(which': 0.31; 'code': 0.31; 'that.': 0.31; 'calculated': 0.31; 'fine,': 0.31; 'supposed': 0.32; 'themselves': 0.32; 'run': 0.32; 'text': 0.33; 'running': 0.33; 'comment': 0.34; 'basic': 0.35; 'display': 0.35; 'problem.': 0.35; 'something': 0.35; 'test': 0.35; 'but': 0.35; 'there': 0.35; 'instances': 0.36; 'module.': 0.36; 'doing': 0.36; 'entry': 0.36; 'method': 0.36; 'url:org': 0.36; 'wrong': 0.37; 'starting': 0.37; 'depends': 0.38; 'displays': 0.38; 'window': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'itself': 0.39; 'launch': 0.39; 'url:12': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'forum': 0.61; 'new': 0.61; 'received:173': 0.61; 'making': 0.63; 'myself': 0.63; 'teach': 0.65; 'details': 0.65; 'within': 0.65; 'note:': 0.66; 'url:f': 0.68; 'containing': 0.69; 'click': 0.77; 'converter,': 0.84; 'everything,': 0.84; 'experiment': 0.84; 'received:fios.verizon.net': 0.84; 'url:php': 0.85; 'boxes,': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: [tkinter] trouble running imported modules in main program Date: Tue, 06 Aug 2013 19:38:55 -0400 References: <6f47e052-ec39-4894-a527-0d68653d5375@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-173-75-251-66.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130620 Thunderbird/17.0.7 In-Reply-To: <6f47e052-ec39-4894-a527-0d68653d5375@googlegroups.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 43 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1375832351 news.xs4all.nl 15949 [2001:888:2000:d::a6]:60287 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:52086 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 and you do not need to comment it out as it will be ignored when the module is imported. > I have posted all my code to this forum if you need to look at it > > http://python-forum.org/viewtopic.php?f=12&t=5620 Code comments: double and triple spacing code make it painful to read, especiallly in a 10 line box. self.miles_button = tkinter.Button(self.frame3, \ text = 'Miles', \ command = self.conv_miles) Leave off the unneeded \s. > Any idea what im doing wrong here? You got the answer there -- only one mainloop. Revising the code as suggested above will do that. Note: I am a tkinter beginner too, so I would also have to experiment with details to get importable custom widgets, built from tk widgets, right. -- Terry Jan Reedy