from tkinter import * from tkinter import ttk import settings import cage_func import random as rand NORM_FONT = () SUB_HEADER_FONT = ("Arial", 9, "bold") class HelmholtzGUI(Tk): def __init__(self): Tk.__init__(self) Tk.wm_title(self, "Helmholtz Cage Control") Tk.wm_iconbitmap(self, "Helmholtz.ico") self.Menu = TopMenu(self) # displays menu bar at the top mainArea = Frame(self) mainArea.pack(side="top", fill="both", expand=True) mainArea.grid_rowconfigure(0, weight=1) mainArea.grid_columnconfigure(0, weight=1) self.frames = {} # dictionary for storing all pages for F in (TestFrame, StatusDisplay): frame = F(mainArea, self) self.frames[F] = frame frame.grid(row=0, column=0, sticky="nsew") self.show_frame(StatusDisplay) def show_frame(self, key): frame = self.frames[key] # gets correct page from the dictionary frame.tkraise() # brings this frame to the front class TopMenu: def __init__(self, window): print("menu called") menu = Menu(window) window.config(menu=menu) ModeSelector = Menu(menu) menu.add_cascade(label="Mode", menu=ModeSelector) ModeSelector.add_command(label="Full Manual", command=self.manual_mode) def manual_mode(self): print("Switching to manual mode") class TestFrame(Frame): def __init__(self, parent, controller): Frame.__init__(self, parent) print("TestFrame called") one = Label(self, text="One", bg="red") one.pack(fill=X) two = Label(self, text="Two", bg="blue") two.pack() button = ttk.Button(self, text="Print stuff", command=lambda: print_stuff("Hello")) button.pack() class StatusDisplay(Frame): def __init__(self, parent, controller): Frame.__init__(self, parent) print("StatusDisplay called") # ToDo: remove rowCounter = 0 # keep track of which row we are at in the grid layout col = 0 for header in ["X-Axis", "Y-Axis", "Z-Axis"]: # create Column headers headLabel = Label(self, text=header, font=SUB_HEADER_FONT) headLabel.grid(columnspan=2, row=rowCounter, column=col*2, sticky="ew") col = col + 1 # move to next column rowCounter = rowCounter + 1 # increase row counter to place future stuff below header LabelTexts = ["Port:", "Channel:", "Output:"] # define content of row entries rowNo = len(LabelTexts) # get number of label rows columnNo = 3 # number of label columns Labels = [[] for _ in range(columnNo)] # prepare list of lists to contain all labels for row entries in all columns for i in range(0, rowNo): # create label objects for row entries for j in range(columnNo): Labels[j].append(Label(self, text=LabelTexts[i])) col = 0 for LabelCol in Labels: # place row entries in grid layout for all columns for row in range(rowNo): # place row entries LabelCol[row].grid(row=row+rowCounter, column=col*2, sticky="w") col = col + 1 rowCounter = rowCounter + rowNo # increase row counter to place future stuff below this toBeRemoved = Label(self, text="Active TBD") toBeRemoved.grid(row=1, column=1) def print_stuff(stuff): print(stuff) def random_no(): return rand.uniform(0, 20)