List Info

Thread: Make GUI




Make GUI
user name
2007-03-30 12:35:39
Dear All
I wrote a python script which will take  values from a configuration file and perform some operation and give an answer. I would like to make a gui for the script using Tkinter. Could anybody help me to do that? Suppose my script use a variable 'x'; to calculate x^2. I would like to give the value x=2 through a GUI and get the output in the same window. Please help me to find the solution.
Thanking You
Vinu V.
--
VINU VIKRAM
http://iucaa.ernet.in/~vvinuv/
Re: Make GUI
country flaguser name
United States
2007-03-30 13:15:29
#! /bin/env python2.3

from Tkinter import *
from sys import exit

Root = Tk()

InputVar = StringVar()
OutputVar = StringVar()


######################
# BEGIN: class Command
# Pass arguments to functions from button presses and menu 

selections! Nice!
# In your declaration:  ...command = Command(func,
args,...)
# Also use in bind() statements
#   x.bind("<****>", Command(func,
args...))
class Command:
     def __init__(self, func, *args, **kw):
         self.func = func
         self.args = args
         self.kw = kw
     def __call__(self, *args, **kw):
         args = self.args+args
         kw.update(self.kw)
         apply(self.func, args, kw)
# END: class Command




###############################
# BEGIN: XSqCalc(InVar, OutVar)
def XSqCalc(InVar, OutVar):
     Value = InVar.get().strip()
     if Value == "":
         OutVar.set("error")
         return
     Value = float(Value)
     Value = Value*Value
     OutVar.set(str(Value))
     return
# END: def XSqCalc




Label(Root, text = "Enter a value in the fieldnon the
left, click the 
n"X^2"
button and see thenanswer in the field on the
right.").pack(side = TOP)
Sub = Frame(Root)
Entry(Sub, width = 10, textvariable = InputVar, bg =
"white", 
         fg = "black").pack(side = LEFT)
Label(Sub, text = " ").pack(side = LEFT)
Button(Sub, text = "X^2", command =
Command(XSqCalc, InputVar, 
         OutputVar)).pack(side = LEFT)
Label(Sub, text = " ").pack(side = LEFT)
Entry(Sub, width = 10, textvariable = OutputVar, bg =
"white", 
         fg = "black").pack(side = LEFT)
Sub.pack(side = TOP, padx = 5, pady = 5)
Button(Root, text = "Quit", command =
exit).pack(side = TOP)

Root.mainloop()


That python2.3 line at the beginning may need to be changed
for your  
system.
The text of that first Label() should all be on the same
line.

Bob

On Mar 30, 2007, at 11:35, Vinu Vikram wrote:

> Dear All
> I wrote a python script which will take  values from a 

> configuration file and perform some operation and give
an answer. I  
> would like to make a gui for the script using Tkinter.
Could  
> anybody help me to do that? Suppose my script use a
variable 'x' to  
> calculate x^2. I would like to give the value x=2
through a GUI and  
> get the output in the same window. Please help me to
find the  
> solution.
> Thanking You
> Vinu V.
> -- 
> VINU VIKRAM
> http://iucaa.ernet.in/
~vvinuv/
> _______________________________________________
> Tkinter-discuss mailing list
> Tkinter-discusspython.org
> http://mail.python.org/mailman/listinfo/tkinter-discuss

_______________________________________________
Tkinter-discuss mailing list
Tkinter-discusspython.org
http://mail.python.org/mailman/listinfo/tkinter-discuss

Re: Make GUI
user name
2007-03-30 15:35:59
Dear Bob
Thank you very much for your detailed script. I could do my script using this.
Thank you once again
Vinu V.

On 3/30/07, Bob Greschke < bobpasscal.nmt.edu">bobpasscal.nmt.edu> wrote:
#! /bin/env python2.3

from Tkinter import *
from sys import exit

Root = Tk()

InputVar = StringVar()
OutputVar = StringVar()


######################
# BEGIN: class Command
# Pass arguments to functions from button presses and menu
selections! Nice!
# In your declaration: &nbsp;...command = Command(func, args,...)
# Also use in bind() statements
# &nbsp; x.bind(&quot;<****>", Command(func, args...))
class Command:
&nbsp;   ; def __init__(self, func, *args, **kw):
&nbsp;   ; &nbsp; &nbsp; self.func = func
 ; &nbsp; &nbsp; &nbsp;  self.args = args
 ; &nbsp; &nbsp; &nbsp;  self.kw = kw
 &nbsp;   def __call__(self, *args, **kw):
&nbsp; &nbsp; &nbsp;   ; args = self.args+args
   ; &nbsp; &nbsp;  kw.update( self.kw)
 &nbsp; &nbsp; &nbsp;   apply(self.func, args, kw)
# END: class Command




###############################
# BEGIN: XSqCalc(InVar, OutVar)
def XSqCalc(InVar, OutVar):
&nbsp;   ; Value = InVar.get().strip()
 &nbsp; &nbsp; if Value == "&quot;:
 &nbsp;   ; &nbsp;  OutVar.set("error")
&nbsp; &nbsp;   ; &nbsp; return
&nbsp; &nbsp;  Value = float(Value)
 &nbsp; &nbsp; Value = Value*Value
 &nbsp; &nbsp; OutVar.set(str(Value))
 &nbsp; &nbsp; return
# END: def XSqCalc




Label(Root, text = "Enter a value in the fieldnon the left, click the
n";X^2"
button and see thenanswer in the field on the right.&quot;).pack(side = TOP)
Sub = Frame(Root)
Entry(Sub, width = 10, textvariable = InputVar, bg = "white",
 &nbsp;   ; &nbsp;  fg = "black").pack(side = LEFT)
Label(Sub, text = " ").pack(side = LEFT)
Button(Sub, text = "X^2&quot;, command = Command(XSqCalc, InputVar,
 &nbsp; &nbsp; &nbsp;   OutputVar)).pack(side = LEFT)
Label(Sub, text = " ").pack(side = LEFT)
Entry(Sub, width = 10, textvariable = OutputVar, bg = "white",
 &nbsp; &nbsp; &nbsp;   fg = "black").pack(side = LEFT)
Sub.pack(side = TOP, padx = 5, pady = 5)
Button(Root, text = "Quit", command = exit).pack(side = TOP)

Root.mainloop()


That python2.3 line at the beginning may need to be changed for your
system.
The text of that first Label() should all be on the same line.

Bob

On Mar 30, 2007, at 11:35, Vinu Vikram wrote:

&gt; Dear All
> I wrote a python script which will take  values from a
> configuration file and perform some operation and give an answer. I
> would like to make a gui for the script using Tkinter. Could
> anybody help me to do that? Suppose my script use a variable 'x'; to
> calculate x^2. I would like to give the value x=2 through a GUI and
> get the output in the same window. Please help me to find the
> solution.
> Thanking You
> Vinu V.
> --
> VINU VIKRAM
>; http://iucaa.ernet.in/~vvinuv/
> _______________________________________________
> Tkinter-discuss mailing list
> Tkinter-discusspython.org">Tkinter-discusspython.org
> http://mail.python.org/mailman/listinfo/tkinter-discuss




--
VINU VIKRAM
http://iucaa.ernet.in/~vvinuv/
[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )