Skip to content

Instantly share code, notes, and snippets.

@maxiaochuan
Last active April 16, 2020 13:57
Show Gist options
  • Save maxiaochuan/4b7d491ba927bd0b4a98a3d8eaa51122 to your computer and use it in GitHub Desktop.
Save maxiaochuan/4b7d491ba927bd0b4a98a3d8eaa51122 to your computer and use it in GitHub Desktop.
vscode settings
{"lastUpload":"2020-04-16T13:56:54.042Z","extensionVersion":"v3.4.3"}
[
{
"metadata": {
"id": "e337c67b-55c2-4fef-8949-eb260e7fb7fd",
"publisherId": "Shan.code-settings-sync",
"publisherDisplayName": "Shan"
},
"name": "code-settings-sync",
"publisher": "Shan",
"version": "3.4.3"
}
]
{
"sync.gist": "4b7d491ba927bd0b4a98a3d8eaa51122"
}
@StanisJ
Copy link

StanisJ commented Apr 16, 2020

Kalkulator graficzny przy pomocy tkinera

from tkinter import *
#Sinus i Cosinus
import math

Działanie jako input usera

Dzailanie = ""

Funkcja do zmiany działania

def press(num):

global Dzailanie

Dzailanie = Dzailanie + str(num)

# Akcja do wykonania działan
Akcja.set(Dzailanie)

Funkcja do podania ostatecznego działąnia

def equalpress():

try:

    global Dzailanie

    total = str(eval(Dzailanie))

    Akcja.set(total)

    Dzailanie = ""


# Zabezpieczenie
except:

    Akcja.set(" error ")
    Dzailanie = ""

of text entry box

def clear():
global Dzailanie
Dzailanie = ""
Akcja.set("")

if name == "main":
# Ustawienia parametrów okna
gui = Tk()

gui.configure(background="light green")

gui.title("Kalkuloator z węża")

gui.geometry("300x125")


Akcja = StringVar()

# Pole Działania
Dzailanie_field = Entry(gui, textvariable=Akcja)

Dzailanie_field.grid(columnspan=5, ipadx=55)

Akcja.set('Podaj Działanie')


# Przyciski i ich funkcje  przez Lambda
Licz1 = Button(gui, text=' 1 ', fg='black', bg='yellow',
                 command=lambda: press(1), height=1, width=7)
Licz1.grid(row=2, column=0)

Licz2 = Button(gui, text=' 2 ', fg='black', bg='yellow',
                 command=lambda: press(2), height=1, width=7)
Licz2.grid(row=2, column=1)

Licz3 = Button(gui, text=' 3 ', fg='black', bg='yellow',
                 command=lambda: press(3), height=1, width=7)
Licz3.grid(row=2, column=2)

Licz4 = Button(gui, text=' 4 ', fg='black', bg='yellow',
                 command=lambda: press(4), height=1, width=7)
Licz4.grid(row=3, column=0)

Licz5 = Button(gui, text=' 5 ', fg='black', bg='yellow',
                 command=lambda: press(5), height=1, width=7)
Licz5.grid(row=3, column=1)

Licz6 = Button(gui, text=' 6 ', fg='black', bg='yellow',
                 command=lambda: press(6), height=1, width=7)
Licz6.grid(row=3, column=2)

Licz7 = Button(gui, text=' 7 ', fg='black', bg='yellow',
                 command=lambda: press(7), height=1, width=7)
Licz7.grid(row=4, column=0)

Licz8 = Button(gui, text=' 8 ', fg='black', bg='yellow',
                 command=lambda: press(8), height=1, width=7)
Licz8.grid(row=4, column=1)

Licz9 = Button(gui, text=' 9 ', fg='black', bg='yellow',
                 command=lambda: press(9), height=1, width=7)
Licz9.grid(row=4, column=2)

Licz0 = Button(gui, text=' 0 ', fg='black', bg='yellow',
                 command=lambda: press(0), height=1, width=7)
Licz0.grid(row=5, column=1)

lNawias = Button(gui, text=' ( ', fg='black', bg='yellow',
               command=lambda: press("("), height=1, width=7)
lNawias.grid(row=5, column=0)

pNawias = Button(gui, text=' ) ', fg='black', bg='yellow',
                 command=lambda: press(")"), height=1, width=7)
pNawias.grid(row=5, column=2)


Plus = Button(gui, text=' + ', fg='black', bg='blue',
              command=lambda: press("+"), height=1, width=7)
Plus.grid(row=2, column=3)

Minus = Button(gui, text=' - ', fg='black', bg='blue',
               command=lambda: press("-"), height=1, width=7)
Minus.grid(row=3, column=3)

Razy = Button(gui, text=' * ', fg='black', bg='blue',
                  command=lambda: press("*"), height=1, width=7)
Razy.grid(row=4, column=3)

Dzielenie = Button(gui, text=' / ', fg='black', bg='blue',
                command=lambda: press("/"), height=1, width=7)
Dzielenie.grid(row=5, column=3)

Rownasie = Button(gui, text=' = ', fg='black', bg='red',
               command=equalpress, height=1, width=7)
Rownasie.grid(row=5, column=4)

usun = Button(gui, text='Usuń', fg='black', bg='red',
               command=clear, height=1, width=7)
usun.grid(row=4, column='4')

Potega = Button(gui, text=' Potęga ', fg='black', bg='blue',
                command=lambda: press("**"), height=1, width=8)
Potega.grid(row=2, column=4)

Pierwiastek = Button(gui, text=' Pierwiastek ', fg='black', bg='blue',
                command=lambda: press("**(0.5)"), height=1, width=8)
Pierwiastek.grid(row=3, column=4)

#proba sinusa
#Sinus = Button(gui, text=' Sin ', fg='black', bg='blue',
#command=lambda: press("**(0.5)"), height=1, width=8)
#Sinus.grid(row=1, column=6)

# start okna
gui.mainloop()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment