Home > Back-end >  How to add a field in one text input by clicking a button in PySimpleGUI?
How to add a field in one text input by clicking a button in PySimpleGUI?

Time:11-06

Dears,

I'm new in using Stackoverflow & PySimpleGUI... I want add one functionality in my project using PySimpleGUI, So that when I click in one Button, it will insert a text in another Text Field, it's similar principle as creating calculator , but the only difference I need to input some letter from my keyboard too. To make things more clear, I'm having some Special characters which can't be inserted from key board in that text field , So that I use PySimpleGUI to help me on that :

CodePudding user response:

Just update the text of the Input element with the new characters into the Input element.

import PySimpleGUI as sg

sg.theme('DarkBlue3')

words = "This is a book".split(' ')
layout = [
    [sg.Input(key='-IN-')],
    [sg.Push()]   [sg.Button(word, size=4) for word in words],
]
window = sg.Window("Title", layout, finalize=True)

while True:

    event, values = window.read()

    if event == sg.WIN_CLOSED:
        break
    elif event in words:
        text = values['-IN-'].strip()
        text = text   (' ' if text else '')  event
        window['-IN-'].update(text)

window.close()
  • Related