-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent.py
More file actions
82 lines (57 loc) · 2.38 KB
/
content.py
File metadata and controls
82 lines (57 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import gi
gi.require_version('Gtk', '4.0')
gi.require_version('Adw', '1')
from gi.repository import Gtk, Adw
class Content(Adw.Bin):
def __init__(self):
super().__init__()
main_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=12)
self.set_child(main_box)
main_box.set_vexpand(True)
main_box.set_valign(Gtk.Align.CENTER)
main_box.set_halign(Gtk.Align.CENTER)
nested_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=8)
main_box.append(nested_box)
self.result_label = Gtk.Label(label="")
self.result_label.set_markup("<b>Zde se ti zobrazi vysledek(asi)</b>")
nested_box.append(self.result_label)
self.text_field1 = Gtk.Entry()
self.text_field1.set_placeholder_text("Zadej prvni cislo")
nested_box.append(self.text_field1)
self.combo_box = Gtk.ComboBoxText()
self.combo_box.append_text("+")
self.combo_box.append_text("-")
self.combo_box.append_text("*")
self.combo_box.append_text("/")
self.combo_box.set_active(-1)
nested_box.append(self.combo_box)
self.text_field2 = Gtk.Entry()
self.text_field2.set_placeholder_text("Zadej druhe cislo")
nested_box.append(self.text_field2)
result_button = Gtk.Button(label="Vysledek")
result_button.connect("clicked", self.on_button_clicked)
nested_box.append(result_button)
def on_button_clicked(self, result_button):
operation = self.combo_box.get_active_text()
try:
cislo1 = float(self.text_field1.get_text())
cislo2 = float(self.text_field2.get_text())
except ValueError:
self.result_label.set_text("Neplatne cislo")
return
if operation == "+":
result = cislo1 + cislo2
elif operation == "-":
result = cislo1 - cislo2
elif operation == "*":
result = cislo1 * cislo2
elif operation == "/":
if cislo2 != 0:
result = cislo1 / cislo2
else:
self.result_label.set_text("Error")
return
else:
self.result_label.set_text("Vyberte operaci.")
return
self.result_label.set_text(f"Výsledek: {result}")