By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,988 Members | 1,017 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,988 IT Pros & Developers. It's quick & easy.

Tkinter converting entry to int error

P: 2
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
Share this Question
Share on Google+
3 Replies


Expert 100+
P: 614
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

P: 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

Expert 100+
P: 614
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

Post your reply

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