filmov
tv
Python GUI, Tkinter Calculator
Показать описание
Here is the all codes below so you can use and practice by your own.
from tkinter import *
root = Tk()
e = Entry(root, width=16, borderwidth=2, bg="#8e9775", fg="white", font=("Helvetica", 22, "bold"))
def button_click(number):
def button_clear():
def button_add():
global f_num
global math
math = "addition"
f_num = int(first_number)
def button_equal():
if math == "addition":
if math == "subtraction":
if math == "multiplication":
if math == "division":
def button_subtract():
global f_num
global math
math = "subtraction"
f_num = int(first_number)
def button_multiply():
global f_num
global math
math = "multiplication"
f_num = int(first_number)
def button_divide():
global f_num
global math
math = "division"
f_num = int(first_number)
button_1 = Button(root, text='1', bg="#4a503d",fg="white", padx=40, pady=20, command=lambda: button_click(1))
button_2 = Button(root, text='2',bg="#4a503d",fg="white", padx=40, pady=20, command=lambda: button_click(2))
button_3 = Button(root, text='3',bg="#4a503d",fg="white", padx=40, pady=20, command=lambda: button_click(3))
button_4 = Button(root, text='4',bg="#4a503d",fg="white", padx=40, pady=20, command=lambda: button_click(4))
button_5 = Button(root, text='5',bg="#4a503d",fg="white", padx=40, pady=20, command=lambda: button_click(5))
button_6 = Button(root, text='6',bg="#4a503d",fg="white", padx=40, pady=20, command=lambda: button_click(6))
button_7 = Button(root, text='7',bg="#4a503d",fg="white", padx=40, pady=20, command=lambda: button_click(7))
button_8 = Button(root, text='8',bg="#4a503d",fg="white", padx=40, pady=20, command=lambda: button_click(8))
button_9 = Button(root, text='9',bg="#4a503d",fg="white", padx=40, pady=20, command=lambda: button_click(9))
button_0 = Button(root, text='0',bg="#4a503d",fg="white", padx=40, pady=20, command=lambda: button_click(0))
button_add = Button(root, text='+',bg="#4a503d",fg="white", padx=39, pady=20, command= button_add)
button_equal = Button(root, text='=',bg="#4a503d",fg="white", padx=87, pady=20, command= button_equal)
button_clear = Button(root, text='Clear',bg="#4a503d",fg="white", padx=78, pady=20, command=button_clear)
button_subtract = Button(root, text='-',bg="#4a503d",fg="white", padx=40, pady=20, command= button_subtract)
button_multiply = Button(root, text='*',bg="#4a503d",fg="white", padx=41, pady=20, command= button_multiply)
button_divide = Button(root, text='/',bg="#4a503d",fg="white", padx=40, pady=20, command= button_divide)
from tkinter import *
root = Tk()
e = Entry(root, width=16, borderwidth=2, bg="#8e9775", fg="white", font=("Helvetica", 22, "bold"))
def button_click(number):
def button_clear():
def button_add():
global f_num
global math
math = "addition"
f_num = int(first_number)
def button_equal():
if math == "addition":
if math == "subtraction":
if math == "multiplication":
if math == "division":
def button_subtract():
global f_num
global math
math = "subtraction"
f_num = int(first_number)
def button_multiply():
global f_num
global math
math = "multiplication"
f_num = int(first_number)
def button_divide():
global f_num
global math
math = "division"
f_num = int(first_number)
button_1 = Button(root, text='1', bg="#4a503d",fg="white", padx=40, pady=20, command=lambda: button_click(1))
button_2 = Button(root, text='2',bg="#4a503d",fg="white", padx=40, pady=20, command=lambda: button_click(2))
button_3 = Button(root, text='3',bg="#4a503d",fg="white", padx=40, pady=20, command=lambda: button_click(3))
button_4 = Button(root, text='4',bg="#4a503d",fg="white", padx=40, pady=20, command=lambda: button_click(4))
button_5 = Button(root, text='5',bg="#4a503d",fg="white", padx=40, pady=20, command=lambda: button_click(5))
button_6 = Button(root, text='6',bg="#4a503d",fg="white", padx=40, pady=20, command=lambda: button_click(6))
button_7 = Button(root, text='7',bg="#4a503d",fg="white", padx=40, pady=20, command=lambda: button_click(7))
button_8 = Button(root, text='8',bg="#4a503d",fg="white", padx=40, pady=20, command=lambda: button_click(8))
button_9 = Button(root, text='9',bg="#4a503d",fg="white", padx=40, pady=20, command=lambda: button_click(9))
button_0 = Button(root, text='0',bg="#4a503d",fg="white", padx=40, pady=20, command=lambda: button_click(0))
button_add = Button(root, text='+',bg="#4a503d",fg="white", padx=39, pady=20, command= button_add)
button_equal = Button(root, text='=',bg="#4a503d",fg="white", padx=87, pady=20, command= button_equal)
button_clear = Button(root, text='Clear',bg="#4a503d",fg="white", padx=78, pady=20, command=button_clear)
button_subtract = Button(root, text='-',bg="#4a503d",fg="white", padx=40, pady=20, command= button_subtract)
button_multiply = Button(root, text='*',bg="#4a503d",fg="white", padx=41, pady=20, command= button_multiply)
button_divide = Button(root, text='/',bg="#4a503d",fg="white", padx=40, pady=20, command= button_divide)
Комментарии