473,327 Members | 1,979 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,327 software developers and data experts.

Using ".get()" with "entry"(TKinter)?

Hello, I´m new to Python.. so this is a newbee question.

I´d like to put the value enterd in the entryfield in a variable.

I´m trying to build a calculator with python and TKinter, coding it in just python works good. But making it with TK is a bit hard.

This is my unfinished code, i have tryed get() in many ways,.but I cant make it work. I´m only need to get knowledge about using get() now,.. I now there is other thing undone in this code.

#
import Tkinter
from tkSimpleDialog import *
import math
import string

def Add():
xy = x + y


def Sub():
xy = x - y


def Mul():
xy = x * y


def Div():
xy = x / y


root = Tkinter.Tk()

x = Entry(root)
x.grid(row=0, column=0, columnspan=2)

y = Entry(root)
y.grid(row=0, column=2, columnspan=2)

text = Label(root, text="summa")
text.grid(row=1, column=0)

Button(root, text='add', command=Add).grid(row=2, column=0, columnspan=1)
Button(root, text='sub', command=Sub).grid(row=2, column=1, columnspan=1)
Button(root, text='mul', command=Mul).grid(row=2, column=2, columnspan=1)
Button(root, text='div', command=Div).grid(row=2, column=3, columnspan=1)

root.mainloop()

"
Jan 20 '08 #1
3 30163
dazzler
75
no morjesta :D

use: Entry.get(x)
and remember that the text field contains text, so you must convert it to numeric using float() (or double() for greater accuracy)

Expand|Select|Wrap|Line Numbers
  1. import Tkinter
  2. from tkSimpleDialog import *
  3. import math
  4. import string
  5.  
  6. def Add():
  7.     x1 = float(Entry.get(x))
  8.     y1 = float(Entry.get(y))
  9.     xy = x1 + y1
  10.     print xy
  11.  
  12. def Sub():
  13.     x1 = float(Entry.get(x))
  14.     y1 = float(Entry.get(y))
  15.     xy = x1 - y1
  16.     print xy
  17.  
  18. def Mul():
  19.     x1 = float(Entry.get(x))
  20.     y1 = float(Entry.get(y))
  21.     xy = x1 * y1
  22.     print xy
  23.  
  24. def Div():
  25.     x1 = float(Entry.get(x))
  26.     y1 = float(Entry.get(y))
  27.     xy = x1 / y1
  28.     print xy
  29.  
  30. root = Tkinter.Tk()
  31.  
  32. x = Entry(root)
  33. x.grid(row=0, column=0, columnspan=2)
  34.  
  35. y = Entry(root)
  36. y.grid(row=0, column=2, columnspan=2)
  37.  
  38. text = Label(root, text="summa")
  39. text.grid(row=1, column=0)
  40.  
  41. Button(root, text='add', command=Add).grid(row=2, column=0, columnspan=1)
  42. Button(root, text='sub', command=Sub).grid(row=2, column=1, columnspan=1)
  43. Button(root, text='mul', command=Mul).grid(row=2, column=2, columnspan=1)
  44. Button(root, text='div', command=Div).grid(row=2, column=3, columnspan=1)
  45.  
  46. root.mainloop()
  47.  
Jan 21 '08 #2
Thanks,.. I know now what I did wrong. =)
Jan 22 '08 #3
@dazzler
Where did print function display the output on screen...
Means if we want to display them in another entry box how can we put..
Oct 31 '16 #4

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

Similar topics

5
by: Giles Brown | last post by:
I'm feeling quite dumb this morning. I'm trying to build a COM server DLL using py2exe and it ain't working. Here's what ain't working... setup_dll.py based on py2exe sample: """from...
0
by: BW | last post by:
Please ignore the rest of the code, except for the highlighted part (or the line 'ent1=Entry(topf, width=25)' to line 'ent1.insert(INSERT, wrong, if you cannot see the color). You can copy this into...
1
by: Gregor Horvath | last post by:
Hi, I searched the web and docs but cannot figure out whats wrong with this code: #!/usr/bin/python import Tkinter as Tk class testtk(Tk.Frame):
0
by: Adam | last post by:
Hello, I have a small app I am creating to crawl a directory and check that if it is moved to another a location it's path will not break a character limit. Usually the Windows path limit. ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.