PySimpleGUI tutorial 5: Creating a Text Editor executable app

preview_player
Показать описание
Welcome to the 5th video of this PySimpleGUI tutorial series. In this video, I will be showing you how to create an executable text editor app.
Рекомендации по теме
Комментарии
Автор

source:
# Updating windows after event
import os
import PySimpleGUI as pg
# Step 1: Set theme
pg.theme("default1")
# Step 2: Create layout
file_list_column = [
[
pg.Text("Folder"),
pg.In(size=(30, 1), enable_events=True, key="-FOLDER-"),
pg.FolderBrowse(),
],
[
pg.Listbox(
values=[],
enable_events=True,
size=(50, 20),
key="-FILE_LIST-"
)
]
]
file_viewer_column = [
[pg.Text("Choose a file from the list", size=(50, 1))],
[pg.Text("File name: ", size=(70, 3), key="-TOUT-")],
[pg.Multiline(size=(70, 30), key="-TEXT-")]
[pg.Button("Save")]]

layout = [
[
pg.Column(file_list_column),
pg.VSeperator(),

]
]
# Step 3: Create Window
window = pg.Window("File Viewer", layout)
# Step 4: Event loop
folder_location = ""
while True:
event, values = window.read()
if event == pg.WIN_CLOSED or event == "Exit":
break
elif event == "-FOLDER-":
folder_location = values["-FOLDER-"]
try:
files = os.listdir(folder_location)
except:
files = []
file_names = [
file for file in files
if os.path.isfile(os.path.join(folder_location, file))
and file.lower().endswith((".txt", ".csv", ".json", ".py"))
]

elif event == "-FILE_LIST-" and len(values["-FILE_LIST-"]) > 0:
file_selection = values["-FILE_LIST-"][0]
with open(os.path.join(folder_location, file_selection)) as file:
contents = file.read()
window["-TOUT-"].update(os.path.join(folder_location, file_selection))

elif event == "Save" and len(values["-FILE_LIST-"]) > 0:
with open(os.path.join(folder_location, file_selection), "w" ) as file:
file.write(values["-TEXT-"])
# Step 5: Close window
window.close()
exit()

cnlion
Автор

Hi Can you demonstrate how to create a table which could be used to enter data - parent/child relation ship. For example I want to create a new class and add 2 or more students to the class along with other informations, say assigned group name etc. I should be able to select student name from a drop down in the table.

ashG