Python Forum
[PyGUI] How to format output from layout and keys - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: [PyGUI] How to format output from layout and keys (/thread-30271.html)



How to format output from layout and keys - thruss - Oct-13-2020

I have the following code (I know I can format it better, just trying to get the principles working).  I am very new to PySimpleGUI, and doing lots of videos.  The code at the end runs my tasks with their description and date taken from the calendar and prints it correctly, but I wonder if I could have a better layout for the actual output.  It prints it as if it is a dictionary (in {}).  If there is a better way to do it, I am happy to watch a video and work it through, but I am struggling to find something that does not cover the layout of the initial window (layout).  

The code is:
#import libraries
#from datetime import datetime
from db import *
import PySimpleGUI as sg
# open database connection and load any required data
conn = sqlite3.connect('goalsapp.sqlite')
load_data(conn, True)
layout = [
[sg.Text('Add a new task')],
[sg.Text('Task name '), sg.Input(key="task_name1")],
[sg.Text('Description'), sg.Input(key="task_desc1")],
[sg.Input(key='date1'), sg.CalendarButton('See Calendar')],
#[sg.Exit()]
[sg.OK(), sg.Cancel()]
]
#Create Window
window=sg.Window('Title of the window').Layout(layout)
while True:
event,values = window.Read()
if event in ('OK','Cancel'):
if event == 'OK':
task_name = values['task_name1']
description = values['task_desc1']
task_date = values['date1']
break
window.close()
add_task(conn, task_name, description, task_date)

add_task(conn, 'Work experience', "Get some work experience", datetime(2021, 1, 10))
#task, description, date to collect it. Add the
#add_task(conn, 'Job', "Get a job", datetime(2021, 2, 20))
task_list = read_tasks(conn)
for task in task_list:
print(task)
# disconnect and close database
conn.close()


RE: How to format output from layout and keys - Larz60+ - Oct-13-2020

you need to repost your code within code tags so that indentation is preserved.


RE: How to format output from layout and keys - sulo167 - Nov-30-2023

This is an excellent post, wow. I found your material to be quite useful and beneficial. Don't stop spreading the good news. I've bookmarked your site because I found so many useful articles here.