1

Temat: tkinter - dodanie dwóch liczb

import tkinter as tk
#from tkinter import messagebox

def funkcja1():
    a = edit1.get()
    b = edit2.get()
    if a.isdigit() and b.isdigit():
        wynik = int(a)+int(b)
        edit3_text.set(str(wynik))
    #messagebox.showinfo("Wynik", "Tekst!")
    #messagebox.showwarning("Wynik", "Tekst!")

# Tworzenie głównego okna
root = tk.Tk()
root.title("Zadanie nr 1")

# Label + Edit

label1 = tk.Label(root, text = 'a:', width=40)
label1.pack(pady=0)
edit1 = tk.Entry(root, width=30, bg = "yellow")
edit1.pack(pady=5)
#
label2 = tk.Label(root, text = 'b:', width=40)
label2.pack(pady=0)
edit2 = tk.Entry(root, width=30, bg = "yellow")
edit2.pack(pady=5)
#
label3 = tk.Label(root, text = 'wynik a+b:', width=40)
label3.pack(pady=0)
edit3_text = tk.StringVar()
edit3 = tk.Entry(root, width=30, textvariable=edit3_text)
edit3.pack(pady=5)

# Tworzenie przycisku
button1 = tk.Button(root, text="Sprawdź", command=funkcja1, width=30, height=3)
button1.pack(pady=5)

# Uruchamianie głównej pętli okna
root.mainloop()