473,385 Members | 1,983 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,385 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 6157
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 :...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...

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.