Home > other >  Write a python GUI encountered a difficult has not solve out for help
Write a python GUI encountered a difficult has not solve out for help

Time:09-20

Is a new, today is the second day in python, hoping to find help
The import math
The import tkinter as tk
The window=tk. Tk ()
Window. The title (' measuring coordinate transformation)
Window. The geometry (' 200 x100)
L1=tk. Label (window, text='input coordinates, bg=' yellow ', the font=(' Arail, 10), width=10, height=2)
L1. Place (x=10, y=20)
E1=tk. Entry (window, the font=(' Arail, 10), width=8, show=None)
E1. Place (x=90, y=3)
E2=tk. Entry (window, the font=(' Arail, 10), width=8, show=None)
E2. Place (x=90, y=40)
L2=tk. Label (window, text='input rectangular coordinates, bg=' blue ', the font=(' Arail, 10), fg='white', width=10, height=2)
L2. Place (x=10, y=100)
E3=tk. Entry (window, the font=(' Arail, 10), width=8, show=None)
E3. Place (x=90, y=90)
E4=tk. Entry (window, the font=(' Arail, 10), width=8, show=None)
E4. Place (x=90, y=127)
L3=tk. Label (window, text='transformation results, bg=' white ', the font=(' Arail, 10), width=8, height=2)
L3. Place (x=40, y=180)
T=tk. Text (window width=8, height=1)
T.p lace (x=120, y=190)
Def jtranslate () :
A=e1. The get ()
B=(180) math. PI/* e2 in the get ()
X=a * math. Cos (b)
Y=a * math. Sin (b)
T.i nsert (' top ', x, y)
Def ztranslate () :
C=e3. The get ()
D=e4. The get ()
P=math. SQRT (c * c + d * d)
O=math. Degrees (math. Atan (c/d))
T.i nsert (' top ', p, o)
B1=tk. The Button (window, text='polar coordinates to rectangular coordinate, width=20, height=2, bg=' yellow ', the command=jtranslate ())
B1. Place (x=170, y=10)
B2=tk. The Button (window, text='turn rectangular coordinate polar coordinates, width=20, height=2, bg=' blue ', fg='white', the command=ztranslate ())
B2. Place (x=170, y=97)
Window. The mainloop ()

After the operation error below
Traceback (the most recent call last) :
The File "D:/python/translate. Py", line 35, in & lt; module>
B1=tk. The Button (window, text='polar coordinates to rectangular coordinate, width=20, height=2, bg=' yellow ', the command=jtranslate ())
The File "D:/python/translate. Py", line 25, in jtranslate
B=(180) math. PI/* e2 in the get ()
TypeError: can 't multiply sequence by non - int of type' float '

CodePudding user response:

Try: b=(math. PI/180) * int (e2) get ())
Obtained from the input box type content must be converted to an integer, if you're afraid of the input is not the integer, can also be error handling

CodePudding user response:

I need to change the following line also
The value of c and d will converted to an integer

CodePudding user response:

The command=jtranslate () - & gt; The command=jtranslate
The command=ztranslate () - & gt; The command=ztranslate

CodePudding user response:

To:
 b=(180) math. PI/* e2 in the get () 

Error:
 TypeError: can 't multiply sequence by non - int of type' float '

Access to the Internet (Google) search to find the
Python: TypeError: can 't multiply sequence by non - int of type' float '- Stack Overflow
Such as post, but finally found is:
See the other people mentioned, the need to type conversion, realized:
You here is the input string directly when the digital processing
So to see you code e2 is from
 e2=tk. Entry (window, the font=(' Arail, 10), width=8, show=None) 


Searched the
Python tk. Entry
Find the
Python Tkinter text box (Entry) | novice tutorial
Python Tkinter text box to allow the user to enter a line of text strings,
- "it is clear that here is a control
- "so the get (), must be, a string
- "you can add print type of code
That is, the
 b=(180) math. PI/* e2 in the get () 

Instead of
 userInput=e2. The get () 
Print (" type "(userInput)=% s % type (userInput))

Sure the output is: & lt; The class str>
The value of the mean, you get the user input seems to be the value of the digital is string
Example: the user input the 3
Is '3'
the stringInstead of 3 this integer number

So, the solution is, the input (make sure is digital class) string, int (or floating point) :
 userInput=e2. The get () 
Print (" type "(userInput)=% s % type (userInput))
UserInputInt=int (userInput)
# userInputFloat=float (userInput)

Then go to and the value of your other (float type) to multiply in
 b=(math. PI/180) * userInputInt 
# b=(math. PI/180) * userInputFloat

Can, is not an error,
  • Related