इस लेख में, हम देखेंगे कि एक functional application कैसे बनाया जाए जो ratio calculate करता है। इसे पूरी तरह functional बनाने के लिए, हम SpinBox method का उपयोग करेंगे जो आमतौर पर एक value के लिए ideal spinner बनाता है। इस value को frame में spinner widget का उपयोग करके modify किया जा सकता है। इस प्रकार, एक SpinBox object minimum से maximum की range में values लेता है।
पहले, हम एक tkinter frame बनाएंगे जिसके अंदर हम कुछ widgets define करेंगे।
उदाहरण
from tkinter import *
win = Tk()
win.title("Ratio Calculator")
win.geometry("600x500")
win.resizable(0, 0)
# Create text Label for Ratio Calculator
label = Label(win, text="Ratio Calculator", font=('Times New Roman', 25))
# Define the function to calculate the value
def ratio_cal():
a1 = int(a.get())
b1 = int(b.get())
c1 = int(c.get())
val = (b1 * c1) / a1
x_val.config(text=val)
# Add another frame
frame = Frame(win)
frame.pack()
# Create Spin Boxes for A B and C
a = Spinbox(frame, from_=0, to=100000, font=('Times New Roman', 14), width=10)
a.pack(side=LEFT, padx=10, pady=10)
b = Spinbox(frame, from_=0, to=100000, font=('Times New Roman', 14), width=10)
b.pack(side=LEFT, padx=10, pady=10)
c = Spinbox(frame, from_=0, to=100000, font=('Times New Roman', 14), width=10)
c.pack(side=LEFT, padx=10, pady=10)
x_val = Label(frame, text="", font=('Times New Roman', 18))
x_val.pack(side=LEFT)
# Create a Button to calculate the result
Button(win, text="Calculate", command=ratio_cal, borderwidth=3, fg="white", bg="black", width=15).pack(pady=20)
win.mainloop()
आउटपुट
उपरोक्त code चलाने से GUI-based Ratio Calculator बनेगा।
