[Python]StringVar() Class String processing


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [Python]StringVar() Class String processing
# 1  
Old 11-10-2011
[Python]StringVar() Class String processing

I have a requirement where I collect inputs from entry widget in gui(via variables a,b,c) and then output a string like this: -a a -b b -c c.

Hence if I have given a=1 b=2 c=3, The output string is --> -a 1 -b 2 -c 3
or if I have given a=1 b=2 (c left blank) then the output is --> -a 1 -b 2

As of now, I am able to get the values a,b,c in a stringvar class variable, but I am struggling to generate the
desired output string


Code:
from tkinter import *
from tkinter import ttk

def calculate(*args):
    A=str(a.get())  
    B=str(b.get()) 
    C=str(c.get())

    #out.set(A+" "+B+" "+C)





root = Tk()
root.title("Sample nruntest GUI")
mainframe = ttk.Frame(root)
mainframe.grid(column=0,row=1)
mainframe.columnconfigure(0,weight=1)
mainframe.rowconfigure(0,weight=1)
mainframe['relief'] = 'groove'
mainframe['padding'] = (5,5)
mainframe['borderwidth'] = 2
#
a=StringVar()
b=StringVar()
c=StringVar()
out=StringVar()
#
al=ttk.Label(root,text="A").grid(column=0,row=0,sticky=W)
bl=ttk.Label(root,text="B").grid(column=0,row=1,sticky=W)
cl=ttk.Label(root,text="C").grid(column=0,row=2,sticky=W)
out_l=ttk.Label(root,text="Out").grid(column=0,row=3,sticky=W)
ae=ttk.Entry(root,width=10,textvariable=a).grid(column=1,row=0,sticky=E)
be=ttk.Entry(root,width=10,textvariable=b).grid(column=1,row=1,sticky=E)
ce=ttk.Entry(root,width=10,textvariable=c).grid(column=1,row=2,sticky=E)
out_e=ttk.Entry(root,width=10,textvariable=out).grid(column=1,row=3,sticky=E)

button = ttk.Button(root,text="hello",command=calculate).grid(column=0,row=4)
root.mainloop()


Last edited by animesharma; 11-10-2011 at 12:29 AM..
# 2  
Old 11-10-2011
It been a long time since I used python, but I am still part of the python discussion list.

Try to ask your question there: Python-list Info Page!
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. Programming

Python (seleniumrequests)Class, Constructor, Method Not Working

Newbie question. I created a class: class WP(seleniumrequests.PhantomJS): def __init__(self, wpurl='https://blah.org/download/release-archive/', bwppurl='https://blah.org/plugins/browse/popular/'): self.wp=wpurl ... (5 Replies)
Discussion started by: metallica1973
5 Replies

2. Shell Programming and Scripting

Kbd input processing with python

Hi, I'm new to python, and I work on a little program fpr my rapsberry pi. This scenario here is a little Midi sysex app for my Roland D-50 Synthesizer. With an usb attached number keypad I can type numbers from 0 to 9 and the referenced Midi sysex file would be send out to my Roland D-50... (1 Reply)
Discussion started by: sdohn
1 Replies

3. Shell Programming and Scripting

Match string against character class in bash

Hello, I want to check whether string has only numeric characters. The following code doesn't work for me #!/usr/local/bin/bash if ]]; then echo "true" else echo "False" fi # ./yyy '346' False # ./yyy 'aaa' False I'm searching for solution using character classes, not regex.... (5 Replies)
Discussion started by: urello
5 Replies

4. Programming

Size of Derived class, upon virtual base class inheritance

I have the two class definition as follows. class A { public: int a; }; class B : virtual public A{ }; The size of class A is shown as 4, and size of class B is shown as 16. Why is this effect ?. (2 Replies)
Discussion started by: techmonk
2 Replies

5. Programming

C++ string class design and implementation

Hi, I am designing the look-alike C++ string class: #include <iostream> #include <cstring> #include <exception> #include <new> #define ALLOC(N) (char*) new char #define DELETE(P) delete ((char*)(P)) class String { public: // conversions: to C-like type char operator const... (2 Replies)
Discussion started by: royalibrahim
2 Replies

6. UNIX for Advanced & Expert Users

Get pointer for existing device class (struct class) in Linux kernel module

Hi all! I am trying to register a device in an existing device class, but I am having trouble getting the pointer to an existing class. I can create a class in a module, get the pointer to it and then use it to register the device with: *cl = class_create(THIS_MODULE, className);... (0 Replies)
Discussion started by: hdaniel@ualg.pt
0 Replies
Login or Register to Ask a Question