Welcome to Dream.In.Code
Become an Expert!

Join 136,872 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,659 people online right now. Registration is fast and FREE... Join Now!




Tkinter

 
Reply to this topicStart new topic

Tkinter

gijig
4 Jul, 2008 - 02:00 AM
Post #1

New D.I.C Head
*

Joined: 14 May, 2008
Posts: 5

I am creating a GUI for our project DIGITAL CIRCUIT ANALYZER using Tkinter.Usually,inthe interpreter,we type the following code to execute our program.

>>import diganalyzer
>>diganalyzer.function('file1.v')

This i want to be run on clicking the run menu in my GUI.
What system call and code should i include in my GUI for this purpose?
User is offlineProfile CardPM
+Quote Post

numerical_jerome
RE: Tkinter
11 Sep, 2008 - 04:24 PM
Post #2

New D.I.C Head
*

Joined: 16 Sep, 2007
Posts: 21



Thanked: 1 times
My Contributions
well, assuming you are using a Button or MenuButton widget, you would create a method to call digianalyzer.function(file_name)

using a Button as an example:

CODE

>> mb = Frame ( self, relief=FLAT, borderwidth=2 )
>> mb.analyze = Button (mb, text="Analyze Circuit", command=self.call_analysis, relief=GROOVE, width=12)
>> mb.analyze.grid ( row=1, column=0, sticky=E+N+S )
>> mb.analyze.bind ( "<Button-3>", self.call_analysis)


a few notes,

1) the frame is really unnecessary, you can attach your button to what ever parent you want, or even the top level window. I feel frames make an easy way of grouping widgets and tend to use them heavily, ymmv

2) I assume you are using the grid method to place widgets, if not change as needed

3) "mb.analyze.bind ( "<Button-3>", self.call_analysis)" is also superfluous, I include it here as it will probably come up later in your GUI. This method (as called) will connect the right mouse button, "<Button-3>", to your widget, if you have some other action in mind for this button (or any other user input) the bind method can also take those. Additionally, you can have multiple binds.

once you've defined your button, you will need a method to call on clicking it:

CODE

>> fname = 'file1.v'
>> def call_analysis(self):
>>    diganalyzer.function(fname)


Note a few things, first, since I called a method of the object to which my Button belonged (the 'self.call_analysis', vs. say 'call_analysis'), the first argument to my method needs to be 'self', second, there isn't a good way (that I know of) of passing arguments from widget actions (if someone else has found how to do this, I would be very interested to know), hence the passing your filename through a class member approach taken here.

If you would like a method that can take a file name argument, you can get away with this provided you overload. Observe:

CODE

>> fname = 'file1.v'
>> def call_analysis(self, file_in = None):
>>    if file_in == None:
>>        file_in = fname
>>    diganalyzer.function(fname)


which will behave like the above version, but can also be called (for example, from the top level) as
>> self.call_analysis('file2.v')


I hope this helped,

-Jerome

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/3/08 08:04PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month