我为一个包含 19 个函数的简单调用创建了一个 python 脚本。我遇到了问题,因为它无法在 GUI 模式下工作。我必须重新编码整个事情吗?我对GUI不太了解。有人可以在这里帮助我吗?我试过阅读关于 GUI 我只是迷失了这些步骤。
import math
q=1
while q == True:
print("Please select one option from the menu below: ")
print("\t 0: Expression Input")
print("\t 1: Numbers Input")
print("\t 2: Exit \n")
op = int(input("Please enter (0 or 1 or 2): "))
def expression_input(str1):
num3 = eval(str1)
return num3
if op == 0:
expression = input("Please input the expression for calculation: ")
num3 = expression_input(expression)
print(num3)
q = int(input("Press 1 to continue or 0 to exit:"))
exit
elif op == 1:
s = 1
while s == True:
opr = float(input("Please select a method for calculation from 1 to 19 for the required function:\n\n\t1:+\n\t2:-\n\t3:*\n\t4:/\n\t5:power\n\t6:root\n\t7:sin\n\t8:cos\n\t9:tan\n\t10:arccos\n\t11:arcsin\n\t12:arctan\n\t13:log \n\t14:ln \n\t15:factorial\n\t16:hex\n\t17:octal\n\t18:decimal\n\t19:binary\n\t"))
if opr > 19:
print("Wrong choice, please reenter the option")
exit
elif opr <=4:
p=1
numb1=input("Enter the first value for calculation")
numb2=input("Enter the second value for calculation")
while p==True:
if numb1.isdigit():
if numb2.isdigit():
numb1=float(numb1)
numb2=float(numb2)
if opr == 1:
result=numb1+numb2
print (result)
if opr == 2:
result=numb1-numb2
print (result)
if opr == 3:
result=numb1*numb2
print (result)
if opr == 4:
result=numb1/numb2
print (result)
p=0
s=0
q = int(input("Press 1 to continue or 0 to exit:"))
exit
else:
numb2=input("Sorry, the second value is not a number,please re enter the second value")
else:
numb1=input("Sorry,the first value is not a number. Please Re enter the first value")
else :
t=1
numb1=input("Enter the first value for calculation")
while t== True:
if numb1.isdigit():
numb1=float(numb1)
if opr == 5:
numb2=int(input("Enter the power value for calculation"))
result = math.pow(numb1,numb2)
print (result)
if opr == 6:
result = math.sqrt(numb1)
print (result)
if opr == 7:
result = math.sin(numb1)
print (result)
if opr == 8:
result = math.cos(numb1)
print (result)
if opr == 9:
result = math.tan(numb1)
print (result)
if opr == 10:
result = math.acos(numb1)
print (result)
if opr == 11:
result = math.asin(numb1)
print (result)
if opr == 12:
result = math.atan(numb1)
print (result)
if opr == 13:
numb2=float(input("Enter the base value for calculation"))
result = math.log(numb1,[numb2])
print (result)
if opr == 14:
result = math.log1p(numb1)
print (result)
if opr == 15:
result = math.factorial(numb1)
print (result)
if opr == 16:
numb1=int(numb1)
result = hex(numb1)
print (result)
if opr == 17:
numb1=int(numb1)
result = oct(numb1)
print (result)
if opr == 18:
numb1=int(numb1)
result = float(numb1)
print (result)
if opr == 19:
numb1=int(numb1)
result = bin(numb1)
print (result)
q = int(input("Press 1 to continue or 0 to exit:"))
t=0
p=0
s=0
exit
else:
numb1=input("Sorry, it is not a number. Please re enter")
elif op==2 :
q=0
print ("Thank you for using the program. Bye!")
exit
else:
print("Wrong option, Please re enter again")
s=0
exit