1 Replies - 1385 Views - Last Post: 11 September 2008 - 05:24 PM Rate Topic: -----

#1 gijig   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 14-May 08


Posted 04 July 2008 - 03:00 AM

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

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?
Is This A Good Question/Topic? 0
  • +

Replies To: Tkinter

#2 numerical_jerome   User is offline

  • D.I.C Head

Reputation: 12
  • View blog
  • Posts: 167
  • Joined: 16-September 07

Re: Tkinter

Posted 11 September 2008 - 05:24 PM

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:

>> 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:

>> 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:

>> 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,

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1