2015-10-27 153 views
0

我需要一些幫助將這個簡短程序製作成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("") 

回答

0

把一個python腳本變成一個GUI應用程序並不像GUI(myProgram)那麼簡單。你將需要首先進入不同的GUI工具包。在我看來,蟒蛇最好的兩個是Tkinter(發音爲tee-kay-inter)和PyQt

我建議你從Tkinter開始。它內置於Python中,現在應該可以滿足您的需求。 PyQt - 你必須單獨下載 - 通常來說,功能更強大。正如羅伯斯在他的回答中提到的,有很多在線學習Tkinter的教程,我會極力推薦TheNewBoston's(或Bucky的)教程。但是,這只是一個介紹。

+1

WxWidgets也值得一提和指針:https://www.wxwidgets.org/ IMO WxWidgets的學習曲線比PyQt少得多,對初學者來說可能是更好的選擇。一旦你掌握了它,PyQt無疑更強大。 – nigel222

+0

我總是發音爲「Teh-kin-ter」。 –