From 3d047593f3ba4c670c571ced1f727a49e7d5d2cb Mon Sep 17 00:00:00 2001 From: key Date: Tue, 18 Jul 2023 20:23:41 +0200 Subject: [PATCH] test for tkinter --- calculator.py | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++ main.py | 44 +++++++++++++++++++++++++++++++++++ 2 files changed, 107 insertions(+) create mode 100755 calculator.py create mode 100755 main.py diff --git a/calculator.py b/calculator.py new file mode 100755 index 0000000..370a807 --- /dev/null +++ b/calculator.py @@ -0,0 +1,63 @@ +from tkinter import * +from tkinter import ttk + +#This is tha main window usulayy called Root +root = Tk() +root.title("simple Calculator") + +numButtonSizeX=10 +numButtonSizeY=10 +calcScreenSize=50 +buttonPerRow=3 +paddingX=10 +paddingY=10 +buttonPaddingX=50 +buttonPaddingY=20 +boderSize=5 + +#FUNCTIONS It doenst matter if this is before the decalaritions(PYthon Thing). +def buttonClick(number): + screen.insert(0,number) +# Creating a widget label +#Labels +#Buttons +button1 = Button(root, text="1", padx=buttonPaddingX,pady=buttonPaddingY, command=lambda: buttonClick(1)) +button2 = Button(root, text="2", padx=buttonPaddingX,pady=buttonPaddingY, command=lambda: buttonClick(2)) +button3 = Button(root, text="3", padx=buttonPaddingX,pady=buttonPaddingY, command=lambda: buttonClick(3)) +button4 = Button(root, text="4", padx=buttonPaddingX,pady=buttonPaddingY, command=lambda: buttonClick(4)) +button5 = Button(root, text="5", padx=buttonPaddingX,pady=buttonPaddingY, command=lambda: buttonClick(5)) +button6 = Button(root, text="6", padx=buttonPaddingX,pady=buttonPaddingY, command=lambda: buttonClick(6)) +button7 = Button(root, text="7", padx=buttonPaddingX,pady=buttonPaddingY, command=lambda: buttonClick(7)) +button8 = Button(root, text="8", padx=buttonPaddingX,pady=buttonPaddingY, command=lambda: buttonClick(8)) +button9 = Button(root, text="9", padx=buttonPaddingX,pady=buttonPaddingY, command=lambda: buttonClick(9)) +button0 = Button(root, text="0", padx=buttonPaddingX,pady=buttonPaddingY, command=lambda: buttonClick(0)) +buttonPlus = Button(root, text="+", padx=buttonPaddingX,pady=buttonPaddingY, command=lambda: buttonClick()) +buttonClear = Button(root, text="Clear", padx=buttonPaddingX*2,pady=buttonPaddingY, command=lambda: buttonClick()) +buttonEqual = Button(root, text="=", padx=buttonPaddingX*2,pady=buttonPaddingY, command=lambda: buttonClick()) + +#Entry +screen = Entry(root, width=calcScreenSize, borderwidth=boderSize) +screen.grid(row=0, column=0, columnspan=buttonPerRow, padx=paddingX, pady=paddingY) + +#Showing on the screen and aranging them +button1.grid(row=1, column=0) +button2.grid(row=1, column=1) +button3.grid(row=1, column=2) + +button4.grid(row=2, column=0) +button5.grid(row=2, column=1) +button6.grid(row=2, column=2) + +button7.grid(row=3, column=0) +button8.grid(row=3, column=1) +button9.grid(row=3, column=2) + +button0.grid(row=4, column=0) +buttonClear.grid(row=4, column=1, columnspan=2) +buttonPlus.grid(row=5, column=0) +buttonEqual.grid(row=5, column=1, columnspan=2) + +#Main Loop Equivalent of our main(); +root.mainloop() + + diff --git a/main.py b/main.py new file mode 100755 index 0000000..1557026 --- /dev/null +++ b/main.py @@ -0,0 +1,44 @@ +from tkinter import * +from tkinter import ttk + +#This is tha main window usulayy called Root +root = Tk() +root.title("simple Calculator") + +numButtonSizeX=10; +numButtonSizeY=10; +calcScreenSize=50; + + +#FUNCTIONS It doenst matter if this is before the decalaritions(PYthon Thing). +def myClick(): + clicText = "Label 1 Entry is: " + myEntry.get() + myCLickLabel = Label(root, text=clicText) + myCLickLabel.grid(row=5, column=0) + +# Creating a widget label +#Labels +myLabel1 = Label(root, text="Label1") +myLabel2 = Label(root, text="Label2") +#Buttons +myButton1 = Button(root, text="do not press", state=DISABLED, padx=10,pady=10,fg="blue",bg="orange") +myButton2 = Button(root, text="do not press",command=myClick,fg="blue",bg="orange") + +#Entry +myEntry = Entry(root, width=50) +myEntry.insert(0, "Isert Label one's Entry") +myEntry.grid(row=0, column=1) + +#Showing on the screen and aranging them +myLabel1.grid(row=0, column=0) +myLabel2.grid(row=1, column=0) +myButton1.grid(row=3, column=0) +myButton2.grid(row=4, column=0) + + + + +#Main Loop Equivalent of our main(); +root.mainloop() + +