-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGUIs.py
More file actions
74 lines (54 loc) · 2.13 KB
/
GUIs.py
File metadata and controls
74 lines (54 loc) · 2.13 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
__author__ = 'Charlie'
'''
This will build a basic GUI with two frames one
on thet top to accept user input and one below
to dynamically display some generated information.
'''
from tkinter import * # Dont forget this!
class GUI:
'''
This will build a basic GUI with two frames one
on the top to accept user input and one below
to dynamically display some generated information.
'''
def __init__(self, root):
self.root = root
self.root.title('TK') # Add in the title for your window here
self.topFrame = Frame(self.root)
self.topFrame.pack()
# This is the top frame,
# put in the buttons and stuff for user input here
labelExample = Label(self.topFrame, text = "This is a label:",
font=("Arial", 20))
labelExample.pack()
runIt = Button(self.topFrame,
text = "SOME TEXT HERE - This Button makes it go!",
command = self.clicked)
runIt.pack()
def clicked(self):
'''This will create the bottom frame and then
you can populate it with data'''
newData = self.createData()
# stores the data returned in the createData method as newData
self.bottomFrame = Frame(self.root)
self.bottomFrame.pack()
# Put code to populate your bottomFrame with newData here.
'''Example Population of bottomFrame:'''
i = StringVar() # this is the variable to use in the radioButton
for item in newData:
exampleRb = Radiobutton(self.bottomFrame, text = item,
variable = i, value = item)
exampleRb.pack()
def createData(self):
'''This is a method to create the data you want to
put into your GUI'''
# Put code that creates data here.
# Don't forget to return it at the end.
exampleSet = ['a','list','of','data','you','collected','somehow']
return exampleSet
win = Tk()
# initializes a Tk session
app = GUI(win)
# Creates a GUI class with the Tk session
win.mainloop()
# Keeps the window open