I'm working on a program with PySimpleGui that will copy a finished and refined result list to my clipboard when I press the copy button. So far, it's looking good, but when I copy it, I don't want to include the characters G(Goal), A(Assist) and O.G(Own Goal) if the value is not greater than 0 (If the boxes in the program is blank in other words). Right now, when you run this code under, and you Copy it, you will get [G] [A] [O.G] besides the TEAM1 positions GK, CDM, MID and ST. I haven't yet done TEAM2. Will finish it when I have figured this out.
So what I want from this, is some tips on what I should do, to not include these characters. I'm figuring I need to probably make some definitions with some if and else statements, but it might be a little complicated, considering I only am 3-4 months into Python.
Can someone help me?
[Picture of the program][1]
import PySimpleGUI as sg
import pyperclip
SYMBOL_UP = '▶'
SYMBOL_DOWN = '❌'
sg.theme_background_color('#1e1e1e')
sg.theme_text_color("#FAFFFF")
sg.theme_input_background_color("#FAFFFF")
sg.theme_button_color("#494949")
sg.theme_text_element_background_color("#1e1e1e")
sg.theme_element_background_color("#1e1e1e")
def collapse(layout, key):
return sg.pin(sg.Column(layout, key=key))
section1 =[
[sg.Multiline(key="home_subs", size=(20,3))]
]
section2 =[
[sg.Multiline(key="away_subs", size=(20, 3))]
]
section3 =[
[sg.Text("EXTRA")]
]
layout = [
[sg.Text("STATCOUNTER by ClayAces v.1")],
[sg.Text("------------------")],
# HOME TEAM
[sg.Text("HOME TEAM", text_color='#fce784'), sg.Combo(["TEAM1", "TEAM2", "TEAM3","TEAM4","TEAM5","TEAM6"],
default_value="TEAM1", key="TEAM_1", size=(15,1)), sg.InputText(key="TEAM1_Score", size=(3,1))],
[sg.Text("GK:"), sg.InputText(key="HomeGK", size=(14,1)), sg.Text("G:"), sg.InputText("", size=(2,1),
key="homegk_g"), sg.Text("A:"), sg.InputText("", size=(2,1), key="homegk_a"), sg.Text("O.G:"), sg.InputText("", size=(2,1), key="homegk_og")],
[sg.Text("CDM:"), sg.InputText(key="HomeCDM", size=(14,1)), sg.Text("G:"), sg.InputText("", size=(2,1),
key="homecdm_g"), sg.Text("A:"), sg.InputText("", size=(2,1), key="homecdm_a"), sg.Text("O.G:"), sg.InputText("", size=(2,1), key="homecdm_og")],
[sg.Text("MID:"), sg.InputText(key="HomeMID", size=(14,1)), sg.Text("G:"), sg.InputText("", size=(2,1),
key="homemid_g"), sg.Text("A:"), sg.InputText("", size=(2,1), key="homemid_a"), sg.Text("O.G:"), sg.InputText("", size=(2,1), key="homemid_og")],
[sg.Text("ST:"), sg.InputText(key="HomeST", size=(14,1)), sg.Text("G:"), sg.InputText("", size=(2,1),
key="homest_g"), sg.Text("A:"), sg.InputText("", size=(2,1), key="homest_a"), sg.Text("O.G:"), sg.InputText("", size=(2,1), key="homest_og")],
# SECTION 1
[sg.T(SYMBOL_DOWN, enable_events=True, k='-OPEN SEC1-', text_color='#fce784'),
sg.T('Home subs', enable_events=True, text_color='#fce784', k='-OPEN SEC1-TEXT')],
[collapse(section1, '-SEC1-')],
# AWAY TEAM
[sg.Text("AWAY TEAM", text_color='#fce784'), sg.Combo(["TEAM1", "TEAM2", "TEAM3","TEAM4","TEAM5","TEAM6"],
default_value="TEAM2", key="TEAM_2", size=(15,1)), sg.InputText(key="TEAM2_Score", size=(3,1))],
[sg.Text("GK:"), sg.InputText(key="AwayGK", size=(14, 1)), sg.Text("G:"),
sg.InputText("", size=(2, 1), key="Awaygk_g"), sg.Text("A:"), sg.InputText("", size=(2, 1), key="Awaygk_a"),
sg.Text("O.G:"), sg.InputText("", size=(2, 1), key="Awaygk_og")],
[sg.Text("CDM:"), sg.InputText(key="AwayCDM", size=(14, 1)), sg.Text("G:"),
sg.InputText("", size=(2, 1), key="Awaycdm_g"), sg.Text("A:"), sg.InputText("", size=(2, 1), key="Awaycdm_a"),
sg.Text("O.G:"), sg.InputText("", size=(2, 1), key="Awaycdm_og")],
[sg.Text("MID:"), sg.InputText(key="AwayMID", size=(14, 1)), sg.Text("G:"),
sg.InputText("", size=(2, 1), key="Awaymid_g"), sg.Text("A:"), sg.InputText("", size=(2, 1), key="Awaymid_a"),
sg.Text("O.G:"), sg.InputText("", size=(2, 1), key="Awaymid_og")],
[sg.Text("ST:"), sg.InputText(key="AwayST", size=(14, 1)), sg.Text("G:"),
sg.InputText("", size=(2, 1), key="Awayst_g"), sg.Text("A:"), sg.InputText("", size=(2, 1), key="Awayst_a"),
sg.Text("O.G:"), sg.InputText("", size=(2, 1), key="Awayst_og")],
# SECTION 2
[sg.T(SYMBOL_DOWN, enable_events=True, k='-OPEN SEC2-', text_color='#fce784'),
sg.T('Away subs', enable_events=True, text_color='#fce784', k='-OPEN SEC2-TEXT')],
[collapse(section2, '-SEC2-')],
# RESULTS
[sg.Button("COPY RESULTS", key="Copy")],
# SECTION 3
[sg.T(SYMBOL_DOWN, enable_events=True, k='-OPEN SEC3-', text_color='#fce784'),
sg.T('Extras', enable_events=True, text_color='#fce784', k='-OPEN SEC3-TEXT')],
[collapse(section3, '-SEC3-')],
]
window = sg.Window("STATCOUNTER v.1", layout, font="Calibri, 11", element_padding=(3, 3),element_justification='r')
opened1, opened2, opened3 = True, True, True
while True:
event, values = window.read()
print(event, values)
if event == sg.WIN_CLOSED or event == 'Exit':
break
if event.startswith('-OPEN SEC1-'):
opened1 = not opened1
window['-OPEN SEC1-'].update(SYMBOL_DOWN if opened1 else SYMBOL_UP)
window['-SEC1-'].update(visible=opened1)
if event.startswith('-OPEN SEC2-'):
opened2 = not opened2
window['-OPEN SEC2-'].update(SYMBOL_DOWN if opened2 else SYMBOL_UP)
window['-SEC2-'].update(visible=opened2)
if event.startswith('-OPEN SEC3-'):
opened3 = not opened3
window['-OPEN SEC3-'].update(SYMBOL_DOWN if opened3 else SYMBOL_UP)
window['-SEC3-'].update(visible=opened3)
if event == "Copy":
pyperclip.copy(f"""
=-=-=-=-=-=-=-==-=-=-=-=-=-=-=
{'TEAM1'} {values['TEAM1_Score']}-{values['TEAM2_Score']} {'TEAM2'}
{'TEAM1'}
GK: {values['HomeGK']} [{values['homegk_g']}]G [{values['homegk_a']}A] [{values['homegk_og']}O.G]
CDM: {values['HomeCDM']} [{values['homecdm_g']}G] [{values['homecdm_a']}A] [{values['homecdm_og']}O.G]
MID: {values['HomeMID']} [{values['homemid_g']}G] [{values['homemid_a']}A] [{values['homemid_og']}O.G]
ST:{values['HomeST']} [{values['homest_g']}G] [{values['homest_a']}A] [{values['homest_og']}O.G]
SUBS:
{values['home_subs']}
{'TEAM2'}
GK: {values['AwayGK']}
CDM: {values['AwayCDM']}
MID: {values['AwayMID']}
ST: {values['AwayST']}
SUBS:
{values['away_subs']}
=-=-=-=-=-=-=-==-=-=-=-=-=-=-=
""") ```
[1]: https://i.stack.imgur.com/BDpKB.png