Add files via upload · apecodex/python@9dc212b · GitHub
Skip to content

Commit 9dc212b

Browse files
authored
Add files via upload
1 parent 13b2fd4 commit 9dc212b

4 files changed

Lines changed: 491 additions & 0 deletions

File tree

‎Python/convert/convert_1.py‎

Lines changed: 67 additions & 0 deletions

‎Python/convert/convert_1_gul.py‎

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
from tkinter import *
2+
from tkinter import messagebox
3+
import math
4+
5+
class Convert_1():
6+
7+
def __init__(self):
8+
self.mainwindows = Tk()
9+
ws = self.mainwindows.winfo_screenwidth() # Get the monitor width
10+
hs = self.mainwindows.winfo_screenheight() # Get the monitor height
11+
w = 600 # The width of the program
12+
h = 500 # The height of the program
13+
x = (ws / 2) - (w / 2)
14+
y = (hs / 2) - (h / 2)
15+
self.mainwindows.geometry("%dx%d+%d+%d" % (w, h, x, y)) # Centered
16+
self.mainwindows.title("") # The title of the program,Is now empty,Please enter yourself
17+
# self.mainwindows.config(bg="#222") # background
18+
19+
def kiloToMiles(self,kilometers):
20+
21+
# conversion factor
22+
conv_fac = 0.621371
23+
24+
miles = float(kilometers) * conv_fac
25+
self.return_value_Text.delete(0.0, END) # Empty the content
26+
self.return_value_Text.insert(END,'%0.3f kilometers is equal to %0.3f miles' % (kilometers, miles)) # Write content
27+
28+
def celsiusToFahrenheit(self,Celsius):
29+
30+
# conversion factor
31+
Fahrenheit = 9.0 / 5.0 * Celsius + 32
32+
33+
self.return_value_Text.delete(0.0, END) # Empty the content
34+
self.return_value_Text.insert(END,'%0.3f Celsius is equal to %0.3f Fahrenheit' % (Celsius, Fahrenheit)) # Write content
35+
36+
def degreesToradians(self,degrees):
37+
38+
# conversion factor
39+
radians = math.pi * degrees / 180
40+
41+
self.return_value_Text.delete(0.0, END) # Empty the content
42+
self.return_value_Text.insert(END,'%0.3f Degrees is equal to %0.3f Radians' % (degrees, radians)) # Write content
43+
44+
def centimetersToinches(self,centimeters):
45+
46+
# conversion factor
47+
inches = centimeters * 0.3937
48+
49+
self.return_value_Text.delete(0.0, END) # Empty the content
50+
self.return_value_Text.insert(END,'%0.3f Centimeters is equal to %0.3f inches' % (centimeters, inches)) # Write content
51+
52+
def ConfirmtheCalculation(self):
53+
choose = self.var.get()
54+
user_input_value = self.Enter_Entry.get()
55+
if choose == 0:
56+
messagebox.showinfo(title="Remind",message="Please select an option") # There is no choice of conversion button, jump out of the prompt
57+
elif user_input_value.strip() == "":
58+
messagebox.showinfo(title="Remind", message="Please enter the value to be converted") # No input, jump out of the prompt box
59+
elif [value for value in user_input_value if value.isalpha()] != []:
60+
messagebox.showinfo(title="Remind", message="Please enter a number, not a string") # The contents of the input string, jump out of the prompt box
61+
elif choose == 1: # If selected Kilometres to Miles
62+
self.kiloToMiles(int(user_input_value))
63+
elif choose == 2: # If selected Celsius to Fahrenheit
64+
self.celsiusToFahrenheit(int(user_input_value))
65+
elif choose == 3: # If selected Degrees to Radians
66+
self.degreesToradians(int(user_input_value))
67+
elif choose == 4: # If selected Centimeters to Inches
68+
self.centimetersToinches(int(user_input_value))
69+
else:
70+
pass # Easy to expand
71+
72+
73+
def main(self):
74+
self.var = IntVar() # Initialize options
75+
remind_label = Label(self.mainwindows,text="Select the button to convert",font=("宋体",25)).pack()
76+
KTM_btn = Radiobutton(self.mainwindows,text="Kilometres to Miles",variable=self.var,value=1,font=("宋体",15)).place(x=30,y=40) # Kilometres to Miles Button
77+
CTF_btn = Radiobutton(self.mainwindows,text="Celsius to Fahrenheit",variable=self.var,value=2,font=("宋体",15)).place(x=30,y=70) # Celsius to Fahrenheit Button
78+
DTR_btn = Radiobutton(self.mainwindows,text="Degrees to Radians",variable=self.var,value=3,font=("宋体",15)).place(x=350,y=40) # Degrees to Radians Button
79+
CTI_btn = Radiobutton(self.mainwindows,text="Centimeters to Inches",variable=self.var,value=4,font=("宋体",15)).place(x=350,y=70) # Centimeters to Inches Button
80+
Enter_label = Label(self.mainwindows,text="Enter Here: ",font=("宋体",20)).place(x=40,y=150) # Enter the prompt
81+
self.Enter_Entry = Entry(self.mainwindows,font=("宋体",25)) # Enter the value of the conversion
82+
self.Enter_Entry.place(x=220,y=150)
83+
Entry_button = Button(self.mainwindows,text="Confirm the Calculation",font=("宋体",20),relief="solid",command=self.ConfirmtheCalculation).place(x=150,y=250) # Confirm the Calculation Button
84+
self.return_value_Text = Text(self.mainwindows,width=34,height=4,font=("宋体",25),relief="solid") # The value after conversion is output here
85+
self.return_value_Text.place(x=10,y=350)
86+
self.mainwindows.mainloop() # while~
87+
88+
89+
if __name__ == '__main__':
90+
convert = Convert_1()
91+
convert.main()

‎Python/convert/convert_2.py‎

Lines changed: 66 additions & 0 deletions

0 commit comments

Comments
 (0)