from tkinter import *
import tkinter.messagebox as tmsg
root = Tk()
root.title("Temperater Converter")
root.wm_iconbitmap("Temperature.ico")
root.geometry("499x500")
# This function will convert Celcius to fahrenheit
def Convert():
if FahOrCel.get() == 1:
Celsius = Temperature.get()
Fahrenheit = (float(Celcius)*9/5 32)
tmsg.showinfo("Conversion Succsfull!",
f"{Celsius} Celcius is {Fahrenheit} Fahrenheit")
# This function will convert fahrenheit to celcius
elif FahOrCel2.get() == 1:
Fahrenheit = Temperature.get()
Celsius = (float(Fahrenheit) - 32) / 1.8
tmsg.showinfo("Conversion Successfully!",
f"{Fahrenheit} Fahrenheit is {Celsius} Celsius")
# Main Heading of the program
# font="lucida 20 bold"
frame = Frame(root, bg="yellow", borderwidth=10, relief=SUNKEN).grid(row=1, column=3)
# Txt = Label(frame,text="Temperature Converter",fg="green", font="comicsansms 10 bold",padx=15).grid(row=0,column=3)
Txt1 = Label(text="Temperature", font="Cascadia 20").grid(row=4, column=1)
Temperature = IntVar()
TemEnt = Entry(root, textvariable=Temperature, width=10,
font="Cascadia 15 bold").grid(row=4, column=2, padx=5)
FahOrCel = IntVar()
Temp = Checkbutton(text="Celcius", variable=FahOrCel).grid(row=4, column=3)
FahOrCel2 = IntVar()
Temp2 = Checkbutton(text="Fahrenheit",
variable=FahOrCel2).grid(row=4, column=4)
convert = Button(root, text="Convert It!", font="Cascadia 15 bold",
command=Convert).grid(row=15, column=2)
root.mainloop()
當我們運行此代碼時,GUI 沒有正確對齊,當我們添加一些功能或進行一些修改時,GUI 的對齊也不完美。如果我們用任何方法改變它,那么對齊也不正確。
uj5u.com熱心網友回復:
為了使布局具有彈性,您需要
但你可以把它拉伸到例如

轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/512410.html
