-
Notifications
You must be signed in to change notification settings - Fork 0
/
tk_custom_items.py
52 lines (46 loc) · 1.68 KB
/
tk_custom_items.py
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
import tkinter as tk
from tkinter import END
from tkinter.scrolledtext import ScrolledText
from itertools import cycle
class ColorButton(tk.Button):
def __init__(self, *args, **kwargs):
tk.Button.__init__(self, *args, **kwargs)
self.config(width=5, height=3, command=self.b_color)
self.config(bg='grey')
self.cur_color = 'grey'
self.colors = ['green', 'yellow', 'grey']
self.color_gen = cycle(self.colors)
def b_color(self):
self.cur_color = next(self.color_gen)
self.config(bg=self.cur_color)
def reset_button(self):
self.config(text='', bg='grey')
while True:
self.cur_color = next(self.color_gen)
if self.cur_color == 'grey':
break
class AnswerField(ScrolledText):
def __init__(self, *args, **kwargs):
ScrolledText.__init__(self, *args, **kwargs)
self.config(state='disabled')
def print_form(self, l, words_per_line):
"""
Prints entries in list 'l' as an argument-specified words per line. If list is empty, function returns that
there are no word matches.
"""
self.config(state='normal')
self.delete("1.0", END)
if not l:
self.insert(END, 'No word matches found.')
else:
j = 0
for i, word in enumerate(l):
word = word.strip()
if i+1 != len(l):
self.insert(END, f'{word}, ')
j += 1
else:
self.insert(END, f'{word}')
if j % words_per_line == 0:
self.insert(END, f'\n')
self.config(state='disabled')