このテキストを GUI でラップするにはどうすればよいですか? 私はPythonとプログラミング全般にかなり慣れていないので、このコンバーターを最初のプロジェクトとして書きました。プロジェクトを GUI でラップしたいのですが、tkinter について読み始めると、コード全体を書き直さなければならないように見えます。GUIを完全に書き直さずにこれをラップすることは可能ですか?
__Version__ = 0.1
import time
import os
from tkinter import Tk
line_break = "==========_Number_in_Inches_=========="
MM_break = "==========_Enter_MM_To_Convert_=========="
sys_Error = "ValueError, Could not recognize input as a number"
Inches = float(25.4)
def main():
while True:
os.system('CLS')
print("Welcome to the converter")
time.sleep(0.5)
print("What would you like to do?")
time.sleep(0.5)
print("Enter Convert MM or Convert Surface")
function = (input())
time.sleep(0.5)
if function in('Convert','convert'):
con()
elif function in('Surface', 'surface', 'RA', 'ra', 'Ra'):
surf()
elif function in('end', 'kill', 'quit', 'End', 'Kill', 'Quit'):
print("Goodbye")
time.sleep(1.00)
os.system('CLS')
time.sleep(1.00)
break
elif function in('help', 'Help'):
help()
else:
print(sys_Error)
time.sleep(1.0)
def con():
while True:
print("Return = Main Menu, Surface = RA Conversion")
print(MM_break)
number = (input())
if number in('Return', 'return'):
break
elif number in('Surface', 'surface', 'Ra', 'RA', 'ra'):
surf()
elif number in('help', 'Help'):
help()
elif number in('end', 'kill', 'quit', 'End', 'Kill', 'Quit'):
break
else:
try:
float(number)
except ValueError:
print(sys_Error)
break
else:
float_number = float(number)
Convert = float_number/Inches
Results_3 = ("%.3f" % Convert)
Results_4 = ("%.4f" % Convert)
print(line_break)
print(" ")
print('\t', Results_3)
print('\t', Results_4)
print(line_break)
print(" ")
r = Tk()
r.withdraw()
r.clipboard_clear()
r.clipboard_append(Results_3)
def surf():
while True:
print("Please enter Surface Finish")
print("or type return to return to main menu")
surface = (input())
if surface in('Return', 'return'):
break
elif surface in('Convert', 'convert'):
con()
elif surface in('help', 'Help'):
help()
elif surface in('end', 'kill', 'quit', 'End', 'Kill', 'Quit'):
break
else:
try:
float(surface)
except ValueError:
print(sys_Error)
time.sleep(1.0)
break
else:
float_surface = float(surface)
RA_convert = (float_surface/Inches) * 1000
Results = float(RA_convert)
RA_results = ("%.0f" % Results)
print(RA_results)
r = Tk()
r.withdraw()
r.clipboard_clear()
r.clipboard_append(RA_results)
def help():
while True:
print('\t' "If you are having trouble")
print('\t' "Make sure you are prompting the program")
print('\t' "to enter etiher MM conversion mode")
print('\t' "or Surface Conversion mode")
print('\t' "by entering Convert or Surface")
print('\t' "when prompted at startup")
print('\t' "make sure that you are entering a number")
print('\t' "or a recognized command")
print('\t' "The list of commands are as follows")
print('\t' "help = Displays help message")
print('\t' "end = Ends the program")
print('\t' "(also try End, quit, Quit, kill, Kill)")
print('\t' "Convert = MM Conversion mode")
print('\t' "Surface or Ra = Surface conversion mode")
print('\t' "If you are still having problems contact")
print('\t' "Daniel Granado")
print('\t' "at Dan_granado@pennunited.com")
time.sleep(4.0)
print("Press enter to return to main menu")
reload = input()
break
main()