Question

Create a basic integer calculator program that uses two entries, a combo box, two labels, and a button to do basic calculatio

Using Python GUI

from tkinter import *
from tkinter.ttk import *

def main():
window = Tk()
  
window.mainloop()


main()

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Solution: Code: #Import necessary packages from tkinter import* from tkinter.ttk import * #Function for left side value def fcmbo value.set(+) #set the values ㎝bo-value . grid (row=0, column-1) value-left = Entry (window) value-left . grid (row=0,

Copyable Code:

#Import necessary packages
from tkinter import *
from tkinter.ttk import *

#Function for left side value
def func_left():
#Global variable declarations
global value_left, value_right, lbl_result, cmbo_value
#Call the method
value_left.get()

#Function for right side value
def func_right():
#Global variable declarations
global value_left, value_right, lbl_result, cmbo_value
#Call the method
value_right.get()

"""Function for calculation"""
def calculation_cmbo():
#Global variable declarations
global value_left, value_right, lbl_result, cmbo_value

#Calculations
if cmbo_value.get() == "+":
lbl_result['text'] = str(int(value_left.get()) + int(value_right.get()))
elif cmbo_value.get() == "-":
lbl_result['text'] = str(int(value_left.get()) - int(value_right.get()))
elif cmbo_value.get() == "*":
lbl_result['text'] = str(int(value_left.get()) * int(value_right.get()))


#Main method
def main():
#Global variable declarations
global value_left, value_right, lbl_result, cmbo_value
#Call the GUI
window = Tk()
#Values on array
integer_options = ["+", "-", "*"]

#Combo values
cmbo_value = Combobox(window,
values=integer_options)
cmbo_value.set("+")
#Set the values
cmbo_value.grid(row=0, column=1)
value_left = Entry(window)
value_left.grid(row=0, column=0)
value_right = Entry(window)
value_right.grid(row=0, column=2)
calc_button = Button(window, text='Calculate', command=calculation_cmbo)
calc_button.grid(row=1, column=1)
equals_label = Label(window, text="=")
equals_label.grid(row=0,column=3)
lbl_result = Label(window)
lbl_result.grid(row=0, column= 4)
#Call the main loop
window.mainloop()

"""Call main method"""
main()

Add a comment
Know the answer?
Add Answer to:
Using Python GUI from tkinter import * from tkinter.ttk import * def main(): window = Tk()    window.mainloop() main()...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT