Python Forum
[PyGUI] How to format output from layout and keys
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGUI] How to format output from layout and keys
#1
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()
Reply
#2
you need to repost your code within code tags so that indentation is preserved.
Reply
#3
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.
Larz60+ write Nov-30-2023, 09:05 AM:
Link removed
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  pyqt5 layout Nickd12 8 3,401 Jan-18-2021, 09:09 AM
Last Post: Axel_Erfurt
  Python GUI layout off between different OS shift838 5 3,622 Jan-02-2019, 02:53 AM
Last Post: shift838
  [Tkinter] grid layout neech 8 17,493 Oct-14-2016, 07:06 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020