To πρόγραμμα :
Δείτε το εδώ
Κώδικας:
from tkinter import *
screen = Tk()
do = "+"
#----------------------------------Do_It Function----------------------------------#
def Do_It():
global num1, num2, value
#See if there are numbers in the entrys field#
try:
number1 = int(num1.get())
number2 = int(num2.get())
pass
except:
pass
#See if there are numbers in the entrys field#
if do == "+":
value.set(str(number1 + number2))
pass
elif do == "-":
value.set(str(number1 - number2))
pass
elif do == "x":
value.set(str(number1 * number2))
pass
elif do == "/":
value.set(str(number1 / number2))
pass
pass
#----------------------------------Do_It Function----------------------------------#
#-----------------------------------Plus Function----------------------------------#
def Plus():
global text, do
text.set("+")
do = text.get()
pass
#-----------------------------------Plus Function----------------------------------#
#---------------------------------Negative Function--------------------------------#
def Negative():
global text, do
text.set("-")
do = text.get()
pass
#---------------------------------Negative Function--------------------------------#
#----------------------------------Multy Function----------------------------------#
def Multy():
global text, do
text.set("x")
do = text.get()
pass
#----------------------------------Multy Function----------------------------------#
#-----------------------------------Div Function-----------------------------------#
def Div():
global text, do
text.set("/")
do = text.get()
pass
#-----------------------------------Div Function-----------------------------------#
#_____Variables_____#
num1 = StringVar()
num2 = StringVar()
text = StringVar()
text.set("+")
value = StringVar()
value.set("0")
#_____Variables_____#
#Creating the Window
screen.geometry("500x500+400+200")
screen.title("Αριθμομηχανή")
#Building the Entrys.
entry1 = Entry(textvariable = num1).place(x = 10 , y = 25)
label1 = Label(textvariable = text).place(x = 150, y = 25)
label2 = Label(text = "=", fg = "black").place(x = 310, y = 25)
label3 = Label(textvariable = value).place(x = 330, y = 25)
entry2 = Entry(textvariable = num2).place(x = 180, y = 25)
#Buttons.
doit = Button(text = "Υπολόγισε", command = Do_It).place(x = 120, y = 80)
label4 = Label(text = "Διάλεξε Την Πράξη", fg = "black").place(x = 10, y = 125)
plus = Button(text = "+", command = Plus).place(x = 25, y = 150)
nega = Button(text = "-", command = Negative).place(x = 25, y = 180)
mult = Button(text = "x", command = Multy).place(x = 25, y = 210)
div = Button(text = "/", command = Div).place(x = 25, y = 240)
#Credits
CreditsTitle = Label(text = "Credits", fg = "red").place(x = 225, y = 300)
Credits = Label(text = "Made by Nick Babaliaris", fg = "red").place(x = 180, y = 330)
Comment = Label(text = "Crazy program right?", fg = "red").place(x = 190, y = 360)
#####THE END#####
screen.mainloop()
To πρώτο μου πρόγραμμα με γραφικά.