473,387 Members | 1,791 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

change a variable thru a dialog box

How do I change a variable thru an entry dialog box in tkinter or python, as x = 1 and the user changes it to x = 2?? I can't seem to find the answer.
Sep 24 '11 #1

✓ answered by bvdet

Assign textvariable to the IntVar.

Expand|Select|Wrap|Line Numbers
  1. from Tkinter import *
  2.  
  3. master = Tk()
  4.  
  5. master.title("test")
  6.  
  7. w = Canvas(master, width=500, height=500)
  8. w.pack()
  9.  
  10. w.config(background="black")
  11.  
  12. defv = 100
  13. a = IntVar()
  14. a.set(defv)
  15. v2 = a.get()
  16.  
  17. e = Entry(master, textvariable=a)
  18. e.pack()
  19.  
  20. def callback():
  21.     v2 = a.get()
  22.     w.create_text(100, 100, font="Purisa", text=v2, fill="white")
  23.  
  24. c = Button(master, text="change", width=10, command=callback)
  25. c.pack()
  26.  
  27. master.mainloop()

3 2255
bvdet
2,851 Expert Mod 2GB
Jay,

Could you post the code you tried? Have you created a textvariable?
Sep 25 '11 #2
Hi, thanks for your reply. This is the code I've been trying with. I can write a variable on the window but I haven't been able to start with a default value then change it through the entry widget. Please help it is driving me crazy.

Expand|Select|Wrap|Line Numbers
  1. from Tkinter import *
  2.  
  3. master = Tk()
  4.  
  5. master.title("test")
  6.  
  7. w = Canvas(master, width=500, height=500)
  8. w.pack()
  9.  
  10. w.config(background="black")
  11.  
  12. defv = 100
  13. a = IntVar()
  14. a.set(defv)
  15. v2 = a.get()
  16.  
  17. e = Entry(master)
  18. e.pack()
  19.  
  20. def callback():
  21.     v = e.get()
  22.     a.set(v)
  23.     v2 = a.get()
  24.     w.create_text(100, 100, font="Purisa", text=v2, fill="white")
  25.  
  26. c = Button(master, text="change", width=10, command=callback)
  27. c.pack()
  28.  
  29. master.mainloop()
  30.  
Sep 25 '11 #3
bvdet
2,851 Expert Mod 2GB
Assign textvariable to the IntVar.

Expand|Select|Wrap|Line Numbers
  1. from Tkinter import *
  2.  
  3. master = Tk()
  4.  
  5. master.title("test")
  6.  
  7. w = Canvas(master, width=500, height=500)
  8. w.pack()
  9.  
  10. w.config(background="black")
  11.  
  12. defv = 100
  13. a = IntVar()
  14. a.set(defv)
  15. v2 = a.get()
  16.  
  17. e = Entry(master, textvariable=a)
  18. e.pack()
  19.  
  20. def callback():
  21.     v2 = a.get()
  22.     w.create_text(100, 100, font="Purisa", text=v2, fill="white")
  23.  
  24. c = Button(master, text="change", width=10, command=callback)
  25. c.pack()
  26.  
  27. master.mainloop()
Sep 25 '11 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Wayne Wengert | last post by:
I want to change the title in the Open Dialog box to something more descriptive for my users but the following code has no effect? I also notice that if the user clicks "Cancel" when the dialog...
1
by: kuba | last post by:
hello i've problem. here is sample code: <SCRIPT LANGUAGE="JavaScript"> <!-- //var city = NewYork;
1
by: Larry | last post by:
Hi my friends, I'm chaning from VC 6 to VC.net. It's easy to add member variable for a control in dialog box class. But when I want to delete it. I have to go to 3 places 1. Variable...
3
by: PawelSokolowski | last post by:
Hi all, I have just switched from VC++ 6.0 to .NET and I am a bit confused. I am very upset that Class Wizard is gone. I am trying to add member variables to my dialog class. When I add control...
2
by: André | last post by:
I try to initialize some Public Variable in a class use for code-behind The idea is to check all uxMsgXXX variables, declare in top of my class and assign the string value from a DB request. Why...
1
by: kapccoe | last post by:
Hello how can i adjust formula thru SQLServer?? for example --the computation Gross Salary less Deduction then the total will be for computing of witholdingTax.. thanks pipz..
0
by: mccanaveras | last post by:
Hi, i have created a dialog-based application which has been designed as single dialog. Now i want to call the previously created dialog from another new one. How can i set this last one as the...
5
by: cty0000 | last post by:
I need to set several variable (can be different type) by sub function.. I don't know the count of variable and type, so i used object type and parameter list like below source.. After setData...
3
by: julytweety | last post by:
Hello Everyone, I have a javascript file, which has some variables set. I wanted to change the existing variable names dynamically. For example, In my file i have my variable prefix as S_ (S...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.