-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10-positivesum.py
More file actions
37 lines (28 loc) · 968 Bytes
/
10-positivesum.py
File metadata and controls
37 lines (28 loc) · 968 Bytes
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
import tkinter as tk
import tkinter.messagebox as mb
mainw = tk.Tk()
mainw.title("Сумма положительных элементов")
mainw.geometry("250x165")
box = tk.Listbox(mainw)
box.grid(row=0, column=0, rowspan=4)
entry = tk.Entry(mainw)
entry.grid(row=0, column=1)
label = tk.Label(mainw)
label.grid(row=1, column=1)
def append_item():
box.insert('end', int(entry.get()))
entry.delete(0, 'end')
def count_sum():
array = []
for item in box.get(0, 'end'):
array.append(item)
positive = [i for i in array if i > 0]
summ = 0
for item in positive:
summ += (item)
label['text'] = "Сумма положительных\nэлементов списка:\n" + str(summ)
buttonAdd = tk.Button(mainw, text="Добавить", command=append_item)
buttonAdd.grid(row=2, column=1)
buttonCount = tk.Button(mainw, text="Посчитать", command=count_sum)
buttonCount.grid(row=3, column=1)
mainw.mainloop()