Github Link
Basic Python example using Tkinter to form a GUI and prints out the inputs into the terminal. The defaults are populated by global variables with a basic example of form validation using the callback function to bound inputs from 0 to 100.
Screenshots
Example Code
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 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
from tkinter import * from tkinter import ttk, font serialNumberString = "12345" startUpDelay = 1 duration = 10 shutdownTime = 1 numberOfTrials = 5 def runFunction (): try: serialNumberString = SerialNumber_Box.get() startUpDelay = int(StartUp_Box.get()) duration = int(Duration_Box.get()) shutdownTime = int(Shutdown_Box.get()) numberOfTrials = int(Trial_Box.get()) except Exception: print("ERROR: Invalid inputs. Values must be greater than zero and not empty.") return print(" ") print("======================") print(" TEST CONFIGURATION ") print("======================") print(" ") print("Serial Number: " + str(serialNumberString)) print("Startup Delay: " + str(startUpDelay)) print("Test Duration: " + str(duration)) print("Shutdown Time: " + str(shutdownTime)) print("Trials : " + str(numberOfTrials)) print(" ") def callback (input) : if input.isdigit() and int(input)<=100 and int(input)>0: return True elif input == "": return True else: return False window = Tk() window.geometry("400x250") window.title("Data Acquisition") window.columnconfigure(0, weight=1) window.rowconfigure(0, weight=1) reg = window.register(callback) mainframe = ttk.Frame(window, padding="12 12 12 12") mainframe.grid(column=0, row=0) ttk.Label(mainframe,text="Serial Number",font=("Arial",16),width=15,justify=LEFT).grid(row=1,column=1) ttk.Label(mainframe,text="Start Up",font=("Arial",16),width=15,justify=LEFT).grid(row=2,column=1) ttk.Label(mainframe,text="Duration",font=("Arial",16),width=15,justify=LEFT).grid(row=3,column=1) ttk.Label(mainframe,text="Shutdown",font=("Arial",16),width=15,justify=LEFT).grid(row=4,column=1) ttk.Label(mainframe,text="Trials",font=("Arial",16),width=15,justify=LEFT).grid(row=5,column=1) SerialNumber_Box = Entry(mainframe, width=10, font=("Arial", 16)) SerialNumber_Box.grid(row=1, column=2) SerialNumber_Box.insert(0,serialNumberString) StartUp_Box = Entry(mainframe, width=10, font=("Arial", 16)) StartUp_Box.grid(row=2, column=2) StartUp_Box.insert(0,startUpDelay) StartUp_Box.config(validate="key", validatecommand=(reg, '%P')) Duration_Box = Entry(mainframe, width=10, font=("Arial", 16)) Duration_Box.grid(row=3, column=2) Duration_Box.insert(0,duration) Duration_Box.config(validate="key", validatecommand=(reg, '%P')) Shutdown_Box = Entry(mainframe, width=10, font=("Arial", 16)) Shutdown_Box.grid(row=4, column=2) Shutdown_Box.insert(0,shutdownTime) Shutdown_Box.config(validate="key", validatecommand=(reg, '%P')) Trial_Box = Entry(mainframe, width=10, font=("Arial", 16)) Trial_Box.grid(row=5, column=2) Trial_Box.insert(0,numberOfTrials) Trial_Box.config(validate="key", validatecommand=(reg, '%P')) ttk.Label(mainframe,text="",font=("Arial",15),width=20,justify=LEFT).grid(row=6,column=1,columnspan=2) f = font.Font(weight="bold",size=18,family="Arial") btn = Button(mainframe, text="RUN", command=runFunction,width=20,bg="green",fg="white",activebackground="white",activeforeground="green") btn['font'] = f btn.grid(row=7,column=1,columnspan=2) ttk.Label(mainframe,text="",font=("Arial",16),width=15,justify=LEFT).grid(row=8,column=1,columnspan=2) window.mainloop() |