このスクリプトは、あなたがそれを子要素ごとにレイアウトをループし、レイアウト情報とするためのオプションを返す、指定されたスタイルのためにそう
import tkinter as tk
from tkinter import ttk
root = tk.Tk()
c = ttk.Combobox(root)
c.grid()
style = 'TCombobox'
s = ttk.Style()
elements = s.layout(style)
def get_element_details(elem, _dict, depth=1):
print('%selement: %s' % (''.join(['\t' for s in range(depth)]), elem))
for key in _dict:
if key != 'children':
print('%s%s: %s' % (''.join(['\t' for s in range(depth+1)]), key, _dict[key]))
print('%soption: %s' % (''.join(['\t' for s in range(depth+1)]), s.element_options(elem)))
if 'children' in _dict:
for child, child_dict in _dict['children']:
get_element_details(child, child_dict, depth+1)
print('element: %s' % style)
print('option: %s' % str(s.element_options(style)))
for elem, elem_dict in elements:
get_element_details(elem, elem_dict)
「フードの下」に何が起こっているか見るのを助ける必要がありますそれぞれ再帰的に。
コンボボックスのためにこれを実行しているときに私が取得:
element: TCombobox
option:()
element: Combobox.field
sticky: nswe
option:()
element: Combobox.downarrow
side: right
sticky: ns
option:()
element: Combobox.padding
expand: 1
sticky: nswe
option: ('-padding', '-relief', '-shiftrelief')
element: Combobox.focus
expand: 1
sticky: nswe
option: ('-focusfill',)
element: Combobox.textarea
sticky: nswe
option: ('-font', '-width')
しかし、私がしようとしたとき:Windows上の
s.configure('Combobox.padding', relief='flat', shiftrelief='flat')
または
s.configure('TCombobox.padding', relief='flat', shiftrelief='flat')
を私はの変化を見ていませんPythonバインディングでは実装されていない可能性があります。
編集: も(仕事の公平なビットで)あなたのスタイルにこれらのサブウィジェットを再できることを意味し、他のTkinterのウィジェットからウィジェットを構築するライブラリPwmありますが、私は、PWMからのコンボボックスは、TTKのより悪いに見える見つけますバージョン
ttkの代わりにtkinterのボタンを使ってみましたか? –
tkinterにはコンボボックスがないので、私はそれを考慮していませんでした。すべてのtkinter(ttkではない)ウィジェットを「平坦化」(境界線なし、救済なしなど)できますか?たぶん、私はコンボボックスの問題を回避することができます。 – user3486991
tkinterとttkの両方のウィジェットを同じアプリケーションで使用できます。一般的に言えば、tkinterウィジェットはttkウィジェットよりも(あるいは少なくとも、より簡単に設定できる)はるかに設定可能です。 –