Skip to content

Commit dc6f2ed

Browse files
committed
Completed exercise ten.A
1 parent 417f2e3 commit dc6f2ed

2 files changed

Lines changed: 107 additions & 2 deletions

File tree

src/exerciseten/radiobutton.py

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
import tkinter as tk
2+
3+
4+
class Application:
5+
"""Conceptual class for GUI application
6+
:param master: main window of an application, default to None
7+
:type master: tkinter.Tk
8+
"""
9+
10+
def __init__(self, master: tk.Tk = None):
11+
"""Constructor method
12+
"""
13+
# Parent setting
14+
# # Size of the window
15+
master.geometry('420x420')
16+
17+
# # Title of the window
18+
master.title('Ejercicio 9.A')
19+
20+
# # Max and min window size
21+
master.maxsize(width=400, height=400)
22+
master.minsize(width=220, height=220)
23+
24+
# Variable
25+
self._rbv = tk.IntVar()
26+
27+
# Widgets
28+
self._rb1 = tk.Radiobutton()
29+
self._rb2 = tk.Radiobutton()
30+
self._rb3 = tk.Radiobutton()
31+
self._bt = tk.Button()
32+
33+
# Frame
34+
# # Init main frame
35+
self._main = tk.Frame(master=master, height=420, width=420)
36+
self._main.grid_propagate(False)
37+
self._main.pack(fill='both', expand=True)
38+
self._main.rowconfigure(index=0, weight=1)
39+
self._main.columnconfigure(index=0, weight=1)
40+
41+
# # Init button frame
42+
self._fb = tk.Frame(master=self._main, height=1, width=1)
43+
self._fb.pack(side='bottom', expand=False)
44+
self._fb.rowconfigure(index=0, weight=1)
45+
self._fb.columnconfigure(index=0, weight=1)
46+
47+
# # Init radio buttons frame
48+
self._frb = tk.Frame(master=self._main, height=1, width=1)
49+
self._frb.pack(side='left', expand=False)
50+
self._frb.rowconfigure(index=0, weight=1)
51+
self._frb.columnconfigure(index=0, weight=1)
52+
53+
# Place widgets into frames
54+
self._createWidgets()
55+
56+
# Start application
57+
master.mainloop()
58+
59+
def _reiniciar(self):
60+
"""Method to restore radio button selections
61+
:return: None
62+
:rtype: NoneType
63+
"""
64+
self._rbv.set(False)
65+
66+
def _createWidgets(self):
67+
"""Method to instance and place button widgets
68+
:return: None
69+
:rtype: NoneType
70+
"""
71+
# Radio buttons
72+
# # Init radio buttons
73+
self._rb1 = tk.Radiobutton(self._frb, text='Opcion 1', value=1, variable=self._rbv)
74+
self._rb2 = tk.Radiobutton(self._frb, text='Opcion 2', value=2, variable=self._rbv)
75+
self._rb3 = tk.Radiobutton(self._frb, text='Opcion 3', value=3, variable=self._rbv)
76+
# # Place radio buttons
77+
self._rb1.grid(column=0, row=0, ipadx=0, ipady=0, padx=10, pady=5, sticky=tk.W + tk.N)
78+
self._rb2.grid(column=0, row=1, ipadx=0, ipady=0, padx=10, pady=5, sticky=tk.W + tk.N)
79+
self._rb3.grid(column=0, row=2, ipadx=0, ipady=0, padx=10, pady=5, sticky=tk.W + tk.N)
80+
81+
# Button
82+
# # Init button
83+
self._bt = tk.Button(self._fb, command=lambda: self._reiniciar(), text='Reiniciar')
84+
# # Place button
85+
self._bt.grid(column=0, row=0, ipadx=0, ipady=0, padx=10, pady=5, sticky=tk.S)
86+
87+
88+
def mainApp() -> tuple[int, Application or None]:
89+
"""Main function to start Application class
90+
:return: Application class, None when error exist
91+
:rtype: Application
92+
"""
93+
# Main window of an application
94+
root = tk.Tk()
95+
96+
try:
97+
# Class instance
98+
app = Application(master=root)
99+
return 0, app
100+
except tk.TclError:
101+
return 1, None

src/main.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
from exerciseten.radiobutton import mainApp
2+
3+
14
def main():
2-
"""Main script for pythonBootCamp project
5+
"""Main script for exercise nine.A
36
:return: None
47
:rtype: NoneType
58
"""
6-
pass
9+
state, app = mainApp()
10+
exit(state)
711

812

913
if __name__ == '__main__':

0 commit comments

Comments
 (0)