Skip to content
This repository has been archived by the owner on Sep 26, 2020. It is now read-only.

Commit

Permalink
Extract a base app to deal with main_window layouts
Browse files Browse the repository at this point in the history
  • Loading branch information
T0nyX1ang committed Feb 6, 2020
1 parent 7eeb52b commit 4cb6126
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
19 changes: 19 additions & 0 deletions base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import tkinter

class BaseApp(tkinter.Tk):
# This is the base app which create center tkinter layouts
# To reuse it, make it inherited by other app files
def __init__(self, title, width, height):
super(BaseApp, self).__init__()
self.title(title)
self.__geometry(width, height)

def __geometry(self, width, height):
# put window in the center of the screen
offset_width = (self.winfo_screenwidth() - width) // 5 * 2
offset_height = (self.winfo_screenheight() - height) // 5 * 2
self.geometry("%sx%s+%s+%s" % (width, height, offset_width, offset_height))

if __name__ == '__main__':
app = BaseApp('hello', 400, 300)
app.mainloop()
11 changes: 2 additions & 9 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@
import tkinter.filedialog
import tkinter.messagebox
from model import loader
from base import BaseApp

class ConfigApp(object):
# GUI for the config app.
# Need to be called before login and query.

def __init__(self):
# Initialization for the GUI. All of the variables are private here.
self.__main_window = tkinter.Tk()
self.__main_window.title("Configurations")
self.__set__geometry(400, 150)
self.__main_window = BaseApp("Configurations", 400, 150)
self.__status = False

self.__ID = ''
Expand Down Expand Up @@ -41,12 +40,6 @@ def __init__(self):

self.__main_window.mainloop()

def __set__geometry(self, width, height):
# put window in the center of the screen
offset_width = (self.__main_window.winfo_screenwidth() - width) // 5 * 2
offset_height = (self.__main_window.winfo_screenheight() - height) // 5 * 2
self.__main_window.geometry("%sx%s+%s+%s" % (width, height, offset_width, offset_height))

def __load_model(self, model_category, filetypes, loader):
# generic model loader, filetypes work as a filter, loader is a function
model_category = model_category.lower()
Expand Down
5 changes: 2 additions & 3 deletions result.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import tkinter
import tkinter.ttk
from base import BaseApp
from course import score

class ResultApp(object):
def __init__(self, score_table):
# This app should be utilized to show score results
self.__main_window = tkinter.Tk()
self.__main_window.title("Query Results")
self.__set__geometry(800, 600)
self.__main_window = BaseApp("Query Results", 800, 600)
self.__score_frame = tkinter.Frame(self.__main_window)

# Information
Expand Down

0 comments on commit 4cb6126

Please sign in to comment.