Background = "#111"
TitleBackground = "#444"
ContentBackground = "#222"
TextColour = "#CCC"
import tkinter
import math
Window = tkinter.Tk()
Window.geometry("230x200")
Window.resizable(width="FALSE",height="FALSE")
Window.wm_title("Monitor Size Calc")
Window.configure(bg=Background)
TitleLabel = tkinter.Label(Window, text="Monitor Size Calculator", bg=TitleBackground, fg=TextColour, width=32, height=2)
TitleLabel.pack()
TitleLabel.place(x=0,y=0)
DiagonalLabel = tkinter.Label(Window, text="Diagonal:", width=7, bg=Background, fg=TextColour)
DiagonalLabel.pack()
DiagonalLabel.place(x=12,y=45)
DiagonalEntry = tkinter.Entry(Window, width = 15, bg=Background, fg=TextColour)
DiagonalEntry.pack()
DiagonalEntry.place(x=115,y=48)
AspectRatioLabel = tkinter.Label(Window, text="Aspect Ratio:", width=10, bg=Background, fg=TextColour)
AspectRatioLabel.pack()
AspectRatioLabel.place(x=10,y=75)
AspectRatioXEntry = tkinter.Entry(Window, width = 6, bg=Background, fg=TextColour)
AspectRatioXEntry.pack()
AspectRatioXEntry.place(x=115,y=75)
AspectRatioYEntry = tkinter.Entry(Window, width = 6, bg=Background, fg=TextColour)
AspectRatioYEntry.pack()
AspectRatioYEntry.place(x=168,y=75)
AspectRatioColonLabel = tkinter.Label(Window, text=":", bg=Background, fg=TextColour)
AspectRatioColonLabel.pack()
AspectRatioColonLabel.place(x=157,y=74)
WidthLabel = tkinter.Label(Window, text="Width:", bg=Background, fg=TextColour)
WidthLabel.pack()
WidthLabel.place(x=10, y=105)
WidthValueLabel = tkinter.Label(Window, text="", width=12, border="2px", bg=ContentBackground, fg=TextColour)
WidthValueLabel.pack()
WidthValueLabel.place(x=115, y=105)
HeightLabel = tkinter.Label(Window, text="Height:", bg=Background, fg=TextColour)
HeightLabel.pack()
HeightLabel.place(x=10, y=135)
HeightValueLabel = tkinter.Label(Window, text="", width=12, border="2px", bg=ContentBackground, fg=TextColour)
HeightValueLabel.pack()
HeightValueLabel.place(x=115, y=135)
CalculateButton = tkinter.Button(Window, text="Calculate!", bg=Background, fg=TextColour)
CalculateButton.pack()
CalculateButton.place(x=10, y=165)
ErrorLabel = tkinter.Label(Window, text="", width=12, border="2px", bg=ContentBackground, fg=TextColour)
ErrorLabel.pack()
ErrorLabel.place(x=115, y=165)
def Calculate():
....WidthValueLabel.configure(text="")
....HeightValueLabel.configure(text="")
....ErrorLabel.configure(text="")
....try:
........Diagonal = float(DiagonalEntry.get())
........XRatio = float(AspectRatioXEntry.get())
........YRatio = float(AspectRatioYEntry.get())
....except ValueError:
........ErrorLabel.configure(text="Invalid input!")
....else:
........Width = math.sqrt((Diagonal**2) * (((XRatio**2) / ((XRatio**2)+ (YRatio**2)))))
........Height = math.sqrt((Diagonal**2) * (((YRatio**2) / ((XRatio**2)+ (YRatio**2)))))
........WidthValueLabel.configure(text=str(Width)[0:10])
........HeightValueLabel.configure(text=str(Height)[0:10])
........ErrorLabel.configure(text="Calculated!")
CalculateButton.configure(command=Calculate)
Window.mainloop()