Data Entry
simpleEntry1.py
import PySimpleGUI as PSGmessage = PSG.Text("Welcome")rows = [[message],[PSG.ReadFormButton("Click me")],[PSG.InputText("Billy Gates")]]form = PSG.FlexForm("This is a form.")form.Layout(rows)while True:button, value = form.Read()if button == "Click me":message.Update("Hello " + value[0])
simpleEntry2.py
import PySimpleGUI as PSGmessage = PSG.Text("Welcome")rows = [[message],[PSG.ReadFormButton("Click me")],[PSG.InputText("Billy Gates", key="fullName")]]form = PSG.FlexForm("This is a form.")form.Layout(rows)while True:button, value = form.Read()if button == "Click me":message.Update("Hello " + value["fullName"])
simpleEntry3.py
import PySimpleGUI as PSGmessage = PSG.Text("Welcome", size=(30, 1),text_color='salmon',font=("Papyrus", 25))rows = [[message],[PSG.ReadFormButton("Click me")],[PSG.InputText("Eat ")],[PSG.InputText("Sleep ")],[PSG.InputText("Fortnite ")],[PSG.InputText("Repeat ")]]form = PSG.FlexForm("This is a form.")form.Layout(rows)while True:button, value = form.Read()sentence = ""for eachWord in value:sentence += eachWordmessage.Update(sentence)
dataEntryList.py
import PySimpleGUI as psgimport datetimeform = psg.FlexForm('Getting data in a list')thisYear = datetime.datetime.now().yearlayout = [[psg.Text("Please enter your Username, Password, Year born")],[psg.Text("Username:"), psg.InputText("3l1te")],[psg.Text("Password:"), psg.InputText("*****")],[psg.Text("Year born:"), psg.InputText("2010")],[psg.Submit(), psg.Cancel()]]button, values = form.LayoutAndRead(layout)print("Button clicked: " + button)print("Username: " + values[0])print("Password: " + values[1])age = thisYear - int(values[2])print("Your Age: " + str(age))
dataEntryDict.py
import PySimpleGUI as psgimport datetimeform = psg.FlexForm('Getting data in a list')thisYear = datetime.datetime.now().yearlayout = [[psg.Text("Please enter your Username, Password, Year born")],[psg.Text("Username:"), psg.InputText("3l1te", key="username")],[psg.Text("Password:"), psg.InputText("*****", key="password")],[psg.Text("Year born:"), psg.InputText("2010", key="yearborn")],[psg.Submit(), psg.Cancel()]]button, values = form.LayoutAndRead(layout)print("Button clicked: " + button)print("Username: " + values["username"])print("Password: " + values["password"])age = thisYear - int(values["yearborn"])print("Your Age: " + str(age))
- Which way do you prefer - getting input values as a list (e.g.
values[0]
) or as a dictionary (e.g.values["username"]
)? - Create a GUI application that asks me for my favourite colour, then says "I love
colour
too!", wherecolour
is the colour that I entered. For example, when your program runs, you might type in "blue", to which the computer will respond "I love blue too!"