-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaskFrame.py
49 lines (37 loc) · 1.55 KB
/
askFrame.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
from tkinter import *
from threading import Condition
import dartConstants
class AskFrame(Frame):
instance = False
def cb(self, e):
if ("Escape" == e.keysym):
self.root.unbind("<KeyPress>")
self.place_forget()
AskFrame.instance = False
else:
if (e.char != ""):
self.answers.append(e.char)
self.lastQuestion += 1
if self.lastQuestion < len(self.questions):
self.questionLabeltext.set(self.questions[self.lastQuestion])
else:
self.userCb(self.answers)
self.root.unbind("<KeyPress>")
self.place_forget()
AskFrame.instance = False
return "break"
def __init__(self, questions, root, userCb):
Frame.__init__(self, root, bg="#bae3d2")
if False == AskFrame.instance:
self.place(relx = 0, rely = 0.7, relwidth = 1, relheight = 0.3)
AskFrame.instance = True
self.questions = questions
self.answers = []
self.lastQuestion = 0
self.userCb = userCb
self.root = root
self.questionLabeltext = StringVar()
self.questionLabeltext.set(questions[0])
label = Label(self, textvariable=self.questionLabeltext, font = (dartConstants.DART_FONT, 80), bg="#bae3d2")
label.place(relx=0.5, rely=0.5,anchor="center")
root.bind("<KeyPress>", lambda e:self.cb(e))