[Question] How do you apply themes to user defined elements

未关闭
#6,649 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
25/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
python
领域
desktop

调研方向

从提供的复现程序开始,尤其检查 typeFrames 函数、其中的 sg.Spin 和 sg.Text 元素,以及 sg.theme('BlueMono') 调用。将用户定义 frame 中的主题控件与常规布局进行比较,并验证预期的主题颜色是否始终一致地应用。

由索引模型根据 Issue 内容生成。

描述

enhancement Port - TK
Type of Issue (Enhancement, Error, Bug, Question)

Question


Operating System

MacOS 12.5.1 Monterey

PySimpleGUI Port (tkinter, Qt, Wx, Web)

tkinter


Versions

Version information can be obtained by calling sg.main_get_debug_data()
Python version: 3.11.5 (main, Sep 11 2023, 08:19:27) [Clang 14.0.6 ]
port: tkinter
tkinter version: 8.6.12
PySimpleGUI version: 4.60.5
PySimpleGUI filename: /Users/ddunbar/anaconda3/lib/python3.11/site-packages/PySimpleGUI/PySimpleGUI.py

Or you can print each version shown in ()

Python version (sg.sys.version)
PySimpleGUI Version (sg.__version__)
GUI Version (tkinter (sg.tclversion_detailed), PySide2, WxPython, Remi)

Tkinter


Your Experience In Months or Years (optional)

Years Python programming experience 5/6y dabbling and more for data science!

Years Programming experience overall 8/9y

Have used another Python GUI Framework? (tkinter, Qt, etc) (yes/no is fine) No

Anything else you think would be helpful?


Troubleshooting

These items may solve your problem. Please check those you've done by changing - [ ] to - [X]

  • Searched main docs for your problem www.PySimpleGUI.org
  • Looked for Demo Programs that are similar to your goal. It is recommend you use the Demo Browser! Demos.PySimpleGUI.org
  • None of your GUI code was generated by an AI algorithm like GPT
  • If not tkinter - looked for Demo Programs for specific port
  • For non tkinter - Looked at readme for your specific port if not PySimpleGUI (Qt, WX, Remi)
  • Run your program outside of your debugger (from a command line)
  • Searched through Issues (open and closed) to see if already reported Issues.PySimpleGUI.org
  • Have upgraded to the latest release of PySimpleGUI on PyPI (lastest official version)
  • Tried using the PySimpleGUI.py file on GitHub. Your problem may have already been fixed but not released
Detailed Description

I'm trying to use a user defined element (UDE) similar what you had in your "Dashboard Mockup" example (here: https://pysimplegui.trinket.io/demo-programs#/graph-element/dashboard-mockup). I can apply the theme to all "sg.xxx" elements in the layout, however the theme doesn't apply to the used defined elements? And I cannot work it out, I may be doing something wrong, but not sure if this is the case or if there is a bug here? I'm trying to get the front end made before I add in the mechanics, as they will need the inputs from the gui to function. I changed the radio buttons in your UDE in the example above and the same thing happens, the spinner is dark and cannot be changed. If you place a spinner in the regular layout it picks up the theme. I can't even manually change the text box colour in the UDE.

Code To Duplicate

A short program that isolates and demonstrates the problem (Do not paste your massive program, but instead 10-20 lines that clearly show the problem)

This pre-formatted code block is all set for you to paste in your bit of code:


import sys
import os
import pandas as pd
#import tkinter as tk
import PySimpleGUI as sg 

sampleNum = [i for i in range(0,100)]
bloodList = {'Heparin blood':'-H-', 'Heparin plasma':'-Hp-', 'EDTA blood':'-E-', 'EDTA plasma':'-Ep-', 'Serum clotted':'-SC-',
            'Serum gel':'-SG-', 'Fluoride Oxalate':'-FO-', 'Glucose':'-Glu-',}
fluidList = {'Ascities (plain)':'-ASCp-', 'Ascities (EDTA)':'-ASCe-', 'Pleural effusion (plain)':'-PEp-', 'Pleural effusion (EDTA)':'-PEe-',
             'Pericaridal effusion (plain)':'-PCEp-','Pericaridal effusion (EDTA)':'-PCEe-', 'Aqueous humour (plain)':'-AHp-',
             'Aqueous humour (EDTA)':'-AHe-'}
swabList = {'VTM oropharyngeal':'-VTMo', 'VTM conjunctival':'-VTMc-', 'VTM nasal':'-VTMn-', 'VTM vaginal':'-VTMv-', 'VTM scab':'-VTMs-',
            'Charcoal oropharyngeal':'-CHARo-', 'Charcoal conjunctival':'-CHARc-', 'Charcoal nasal':'-CHARn-', 'Charcoal vaginal':'-CHARv-',
            'Aimes oropharyngeal':'-AIMo-', 'Aimes conjunctival':'-AIMc-', 'Aimes nasal':'-AIMn-', 'Aimes vaginal':'-AIMv-',
            'Dry oropharyngeal':'-DRYo-', 'Dry conjunctival':'-DRYc-', 'Dry nasal':'-DRYn-', 'Dry vaginal':'-DRYv-'}
faecalList = {'Faeces':'-FAEC-', 'Faeces (3d pool)':'-FAEC3-', 'Faecal swab (any)':'-FAECsw-'}
cytologyList = {'Blood smear':'-SMEARbl-', 'Fluid smear':'-SMEARfl-', 'FNA smear (add site)':'-SMEARfna-'}
otherList = {'Fresh tissue (add site)':'-TISS-', 'Fixed tissue (add site)':'-FTISS-'}

sampleArray = ["2H","1E","1eASC"]
sampleList = ', '.join(sampleArray)

def typeFrames(title, sample_dict):
    layout = [[sg.Text(title,  size=(26,1), justification='center', font='Current 16 underline')]]
    for item, key in sample_dict.items():
        sg.theme('BlueMono'),
        layout += [[sg.Spin(sampleNum, initial_value=0, size=(4,2), readonly=True, enable_events=True, key=key, font='Current 14'), sg.Text(item, font='Current 14')]]
    return sg.Frame('',layout,)

sg.theme('BlueMono')

sampleCol1 = [
            [typeFrames("Bloods", bloodList)], 
            [typeFrames("Fluids", fluidList)],
            [typeFrames("Faecal", faecalList)],
            [typeFrames("Other", otherList)]]

sampleCol2 = [
            [typeFrames("Swabs", swabList)],
            [typeFrames("Cytology", cytologyList)],
            [sg.Button('Generate sample lsit and copy to clipboard', key='-GEN-', size=35, font='Current 14')],
            [sg.Multiline(("add output array here as a string"+"."), size=(35,4), font='Current 14')]]

clinhxLayout = [[sg.T('Clinical history selector')]]

sampleLayout = [ 
        [sg.Text('Select samples submitted: ', font='Current 14')],
        [sg.Spin(sampleNum, initial_value=0)],
        [sg.Column(sampleCol1), sg.Column(sampleCol2)]]

layout = [[sg.Column([[sg.Text('VDS Snippets ', font='Current 30')]]),
        sg.Column([[sg.Button('Exit', font='Current 14')]], key='-EXIT-', element_justification='r', expand_x=True)]]


layout +=[[sg.TabGroup([[sg.Tab('Samples submitted', sampleLayout),
                         sg.Tab('Clinical history', clinhxLayout)]], key='-TAB GROUP-', expand_x=True, expand_y=True, font='Current 14')]]

window = sg.Window("VDS Snippets", layout, keep_on_top=True)

while True:
            event, values = window.read()
            print(event, values)
            out = print(sampleList, end=".")
            #window['-S_OUT-'].update(out)
            if event == sg.WIN_CLOSED or event == 'Exit':
                break
            if event == '-GEN-':
                print('You pressed the button')

window.close()
exit(0)

Screenshot, Sketch, or Drawing
code_screengrab gui_screengrab
Watcha Makin?

I'm building a tool to be used for standardising the input of details about samples submitted to our laboratory, to save errors, style and format differences between users. It'll hopefully make it easier to use the data from the database.

主要语言
Python
星标
13.8k
派生
1.8k
PR 合并指标
30 天内没有已合并 PR

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

PySimpleGUI/PySimpleGUI 的其他 Issue

查看 PySimpleGUI/PySimpleGUI 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。