有没有办法使输出文本可复制(Python PySimpleGUI)

Is there a way to make the output text copyable (Python PySimpleGUI)

import random
import PySimpleGUI as sg


def password_generator(pw_len):
    password = "".join(random.sample(chars, pw_len))
    return password

chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789|!\"£$%&/()=?^é*ç°§;:_è+òàù,.-[]@#{}"
sg.theme('DarkPurple3')

layout = [[sg.Text('Password Generator', font=('Roboto', 20), justification='center')],
          [sg.Text('Set password length: ', size=(15, 1)), sg.InputText(size=(15, 1), key='length')],
          [sg.Text(size=(40,1), key='-OUTPUT-'), ],
          [sg.Button('Generate', size=(15, 1)), sg.Button('Exit', size=(15, 1))]]

window = sg.Window('Password Generator', layout)

while(True):
    event, values = window.read()
    if event == 'Exit':
        break
    elif event == 'Generate' or sg.WINDOW_CLOSED:
        pw_len = int(values['length'])
        window['-OUTPUT-'].update('Your password: ' + password_generator(pw_len))

window.close()

代码输出:password generator

我正在尝试制作一个密码生成器,根据用户选择的长度生成密码。一切正常,但我无法使输出文本可复制,有人可以解释我该怎么做吗?提前谢谢你

Text元素的内容无法选择且不可复制。

为其使用输入或多行元素并设置disabled=True

例如

sg.Input(size=(10,1), disabled=True, text_color=sg.theme_text_color(), disabled_readonly_background_color=sg.theme_text_element_background_color(), key='-OUTPUT-')