import PySimpleGUI as sg import mdb class Add: def __init__(self): #defines the Layout and generates a window layout_adder = [ [sg.Text('Artist')], [sg.InputText(key='ARTIST')], [sg.Text('Title')], [sg.InputText(key='TITLE')], [sg.Text('Album')], [sg.InputText(key='ALBUM')], [sg.Text('Length')], [sg.InputText(key='LENGTH')], [sg.Text('Dance')], [sg.InputText(key='DANCE')], [sg.Text('Comment')], [sg.InputText(key='COMMENT')], [sg.Button('Add'), sg.Button('Cancel')] ] self.add_module = sg.Window('Adding Module', layout_adder, use_custom_titlebar=True) self.helper = mdb.Helper() def run(self): while(True): event, values = self.add_module.read() if event == 'Add': song = values['TITLE'] artist = values['ARTIST'] album = values['ALBUM'] length = values['LENGTH'] dance = values['DANCE'] comment = values['COMMENT'] self.helper.write_song(song=song, artist=artist, album=album, duration=length, dance=dance, comment=comment) if event == 'Cancel' or event == sg.WIN_CLOSED: self.add_module.close() break class Look: def __init__(self): data = [["", "", "", "", "", ""]] layout_look = [ [sg.Input(tooltip="Your info here", key='SEARCH'), sg.Button(tooltip="Press to Search", button_text='Search'), sg.Button(tooltip="close search window", button_text='Cancel')], [sg.Table( headings=["Artist", "Title", "Album", "Duration", "Dance", "Comment"], values=data, background_color='white', alternating_row_color='lightblue', text_color='black', auto_size_columns=True, justification='left', num_rows=min(25, 25), key='Table' ) ]] self.look_module = sg.Window('Searching Module', layout_look, use_custom_titlebar=True) self.helper = mdb.Helper() return def run(self): while(True): event, values = self.look_module.read() if event == 'Search': given = values['SEARCH'] data = self.helper.get_song_beautified(True, *given) if not data: sg.popup_error(f'There was no match found for "{given}"') else: self.look_module['Table'].update(values=data) if event == 'Cancel' or event == sg.WIN_CLOSED: self.look_module.close() break class Main: def __init__(self): layout_main = [ [sg.Button(tooltip="Open Add window", button_text='Add Music', p = (50,50)), sg.Button(tooltip="Open Search window",button_text='Search for music', p = (50,50))] ] self.main_module = sg.Window('MDB', layout_main, use_custom_titlebar=True) def run(self): while (True): event, values = self.main_module.read() if event == 'Add Music': new_window = Add() new_window.run() if event == 'Search for music': new_window = Look() new_window.run() if event == sg.WIN_CLOSED: self.main_module.close() break