Skip to content

Commit 51ffbf0

Browse files
committed
Updated GUI to scale with window size.
1 parent bed8079 commit 51ffbf0

File tree

4 files changed

+11
-10
lines changed

4 files changed

+11
-10
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ A simple gui calculator app written in Python and Tkinter that integrates a CI/C
44
TODO
55
- [x] Basic calculator functionality
66
- [ ] Implement % button
7-
- [ ] Multiple layouts & dynamic scaling
7+
- [~] Multiple layouts & dynamic scaling
8+
- Window scaling is implemented, multiple layouts are still WIP
89
- [ ] Tests and documentation
910
- [ ] CI/CD workflow using actions

calculator/gui/button.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ def create_gui(self, root, layout=LAYOUT_STANDARD, width=4):
2424
button.grid(column=i%width, row=int(i/width), sticky=tk.NSEW)
2525

2626
for i in range(width):
27-
self.frame.grid_columnconfigure(i, uniform="calc_buttons")
27+
self.frame.grid_columnconfigure(i, uniform="calc_buttons", weight=1)
28+
29+
for i in range(int(len(layout)/width)):
30+
self.frame.grid_rowconfigure(i, weight=1)
2831

2932
def update(self):
3033
pass

calculator/gui/display.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ def create_gui(self, root):
1212
self.frame = tk.Frame(root)
1313
self.upper_entry = tk.Entry(self.frame, state=tk.DISABLED, justify=tk.RIGHT)
1414
self.lower_entry = tk.Entry(self.frame, state=tk.DISABLED, justify=tk.RIGHT)
15-
self.upper_entry.grid(row=0, sticky=tk.NSEW)
16-
self.lower_entry.grid(row=1, sticky=tk.NSEW)
15+
self.upper_entry.pack(fill=tk.BOTH,expand=True,side=tk.TOP)
16+
self.lower_entry.pack(fill=tk.BOTH,expand=True,side=tk.BOTTOM)
1717

1818
def update(self):
1919
self.upper_entry.configure(state=tk.NORMAL)

calculator/main.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,15 @@
55
if __name__ == "__main__":
66
c = calc.Calculator()
77
main = tk.Tk()
8-
main.title = "Calculator"
9-
main.grid_rowconfigure(0, weight=1)
10-
main.grid_rowconfigure(1, weight=2)
11-
main.grid_columnconfigure(0, weight=1)
8+
main.title("Calculator")
129

1310
calc_display = display.CalculatorDisplay(c)
1411
calc_display.create_gui(main)
15-
calc_display.frame.grid(row=0,sticky=tk.NSEW)
12+
calc_display.frame.pack(fill=tk.BOTH,expand=True,side=tk.TOP,padx=10,pady=(10,0))
1613

1714
calc_buttons = button.CalculatorButtons(c)
1815
calc_buttons.create_gui(main)
19-
calc_buttons.frame.grid(row=1,sticky=tk.NSEW)
16+
calc_buttons.frame.pack(fill=tk.BOTH,expand=True,side=tk.BOTTOM,padx=10,pady=(0,10))
2017

2118
while True:
2219
calc_buttons.update()

0 commit comments

Comments
 (0)