提示输入

时间:2015-10-27 00:49:55

标签: python user-interface

我需要一些帮助才能将这个简短的程序变成GUI。我希望它提示A点,然后继续完成该程序。我只是对如何使用tkinter这样做感到困惑。任何帮助表示赞赏

import sys

while True:

num_sales=int(input("How many sales were completed? "))  # POINT A

while num_sales < 0:
    print("Error. Number of sales cannot be less than 0.")
    print("")
    num_sales=int(input("How many sales were completed? "))

number = 0
total_sales = 0


while number < num_sales:



    sale = float(input("Sale amount: "))


    while sale < 0:
        print("Error. The sale value cannot be less than 0.")
        print("")
        sale = float(input("Sale amount: "))



    number += 1
    total_sales += sale



print("The total sales are $",total_sales)


if total_sales < 10000:
    commission = (8.2/100)*(total_sales)
    print("Total commission is $",commission)

elif 10000 < total_sales < 25000:
    commission = (17/100)*(total_sales)
    print("Total commission is $",commission)

elif total_sales > 25000:
    commission = (23.25/100)*(total_sales)
    print("Total commission is $",commission)

else:
    print("Unknown Error.")
    sys.exit()

print("")

done = input("Are you finished running commissions? (Y/N) ")

if done == "Y":
    sys.exit()

elif done == "y":
    sys.exit()

print("")

1 个答案:

答案 0 :(得分:0)

将python脚本转换为GUI应用程序并不像GUI(myProgram)那么简单。您需要首先进入不同的GUI工具包。在我看来,python最好的两个是Tkinter(发音为 tee-kay-inter )和PyQt

我建议你从Tkinter开始。它内置于Python中,现在可以满足您的需求。 PyQt - 你必须单独下载 - 通常更强大。正如罗伯斯法官在他的回答中提到的,有很多在线学习Tkinter的教程,我强烈推荐TheNewBoston's(或Bucky's)教程。但是,这些只是一个介绍。