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

Tkinter converting entry to int error

I am trying to finish my program but it comes up with this error....The program asks you how many sides and the length of the sides then draws a shape....

Expand|Select|Wrap|Line Numbers
  1. import tkinter
  2. import turtle
  3. window = tkinter.Tk()
  4.  
  5. def callback():
  6.     pen1 = turtle.Pen()
  7.     for i in range(ent):
  8.         pen1.forward(ent1)
  9.         pen1.right(360/ent)
  10.  
  11.  
  12. lbl = tkinter.Label(window, text="How Many Sides :")
  13. lbl.pack()
  14.  
  15. ent = tkinter.Entry(window)
  16. ent.pack()
  17.  
  18. lbl1 = tkinter.Label(window, text="Length Of Sides :")
  19. lbl1.pack()
  20. ent1 = tkinter.Entry(window)
  21. ent1.pack()
  22.  
  23.  
  24. btn = tkinter.Button(window, text="Draw", command = callback)
  25. btn.pack()
  26. window.title("Shape Creator")
  27. window.geometry("300x300")
  28. window.mainloop()
Nov 28 '14 #1
3 6159
dwblas
626 Expert 512MB
Tkinter variables are not Python variables so you have to convert using get(). The values will have to be cast to an integer as they are strings by default. Change the callback() function to the following to see how it works.
Expand|Select|Wrap|Line Numbers
  1. def callback():
  2.    value=ent.get()
  3.    print("sides =", value, type(value))
  4.    value=ent1.get()
  5.    print("length =", value, type(value))
  6.  
Nov 28 '14 #2
Still coming up with an error(sorry im a noob at python) TypeError: can't multiply sequence by non-int of type 'float'
CODE:
Expand|Select|Wrap|Line Numbers
  1. import tkinter
  2. import turtle
  3. window = tkinter.Tk()
  4.  
  5. def callback():
  6.    value=ent.get()
  7.  
  8.    print("sides =", value, type(int))
  9.    value1=ent1.get()
  10.    print("length =", value1, type(int))
  11.  
  12.    pen1 = turtle.Pen()
  13.    pen1.forward(value1)
  14.    pen1.right(360/value)
  15.  
  16.  
  17. lbl = tkinter.Label(window, text="How Many Sides :")
  18. lbl.pack()
  19.  
  20. ent = tkinter.Entry(window)
  21. ent.pack()
  22.  
  23. lbl1 = tkinter.Label(window, text="Length Of Sides :")
  24. lbl1.pack()
  25. ent1 = tkinter.Entry(window)
  26. ent1.pack()
  27.  
  28.  
  29. btn = tkinter.Button(window, text="Draw", command = callback)
  30. btn.pack()
  31. window.title("Shape Creator")
  32. window.geometry("300x300")
  33. window.mainloop()
Nov 29 '14 #3
dwblas
626 Expert 512MB
You have to post the complete error message to show where the error is occurring to get help on that. See string to integer here for general info on how to convert.
Nov 29 '14 #4

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

Similar topics

2
by: Bob Greschke | last post by:
I can't get Root.option_add("*Entry*highlightthickness", "2") Root.option_add("*Entry*highlightcolor", "green") to work. Anyone know why? Setting the font, background color, etc. this way...
5
by: lottaviano | last post by:
I am using Access 2002 and have two tables (Main and Actions) linked (in Relationships) on one field "CAL_ID" (primary key in Main Table). Main Table is a list of equipment. Actions Table lists...
1
by: Arne | last post by:
Hello ! I want to create entry widgets dynamically. var = i=0 for x in var: textbox = "t_", x textbox = entry(frame) textbox.grid(row=4+i, column=0) i = i + 1
5
by: baur79 | last post by:
Hi guys i try to run this code in loop and to pass even the entry is duplicated def email_insert_in_db(email): sql="INSERT INTO emails (email) values ('%s') "%(email)...
3
by: patelxxx | last post by:
I'm trying to update a template on our Content Management System, however getting the following error. I know its difficult to know what the problem is without looking at the PERL coding, however...
1
by: alivip | last post by:
I integrat program to be GUI using Tkinter I try browser direction as you can see # a look at the Tkinter Text widget # use ctrl+c to copy, ctrl+x to cut selected text, # ctrl+v to...
2
by: defn noob | last post by:
from Tkinter import * import os master = Tk() w = Canvas(master, width=800, height=600) print os.path.exists('C:/me/saftarn/desktop/images/blob4.jpg') im = PhotoImage(file =...
2
Thekid
by: Thekid | last post by:
I have a toplevel window in tkinter that has some entry fields. Is there a way that I can get it to change the letters typed in it to uppercase, either as they're typed or after they're typed, while...
2
Thekid
by: Thekid | last post by:
I've hit another snag with tkinter and mysql. After the last post, I'm able to now have a user login that when username and password are entered, a successful mysql connection can be made. The...
1
by: waqasahmed996 | last post by:
Hi I am facing a strange problem. I have a duplicate entry message even though i am using IGNORE in query. My query is insert ignore into table1 select * from table2 Error is: Error Code :...
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: 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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.