I've been practising trying to write my code neater, so decided to build a practice GUI, the code works, However, how could I tidy this up in terms of separating out the different parts of the GUI, such as a separate defs for labels, Combobox etc? or using a function for the 'with open' section.
from tkinter import*
from tkinter.ttk import *
root = Tk()
class GUI:
def __init__(self, master):
self.master = master
master.title('PATM Generator')
master.geometry('+600+300')
#Label1
master.label1 = Label(root, text = 'Select test bed:')
master.label1.grid(row = 0, column = 0, padx = 10, pady = 5)
#Combobox
master.combo = Combobox(root)
master.combo.grid(row =1, column = 0)
master.combo['values'] = (TB)
#Label2
master.label2 = Label(root, text = 'Enter TRD index:')
master.label2.grid(row = 2, column = 0, padx = 10, pady = 5)
#Entry
master.entry = Entry(root)
master.entry.grid(row = 3, column = 0, padx = 10, pady = 0)
#Button
master.button = Button(root, text = 'Append to txt')
master.button.grid(row = 4, padx = 10, pady = 5)
with open('TB.txt') as inFile:
TB = [line for line in inFile]
def main():
GUI(root)
root.mainloop()
main()