2017-05-05 21 views
0

tkinterを使用して、可能であればttkを追加して「モダン」な外観にしたいと考えています。現代のボタン、プルダウンボックスなどは、しばしば縁なしの背景に対して完全に平坦です。私は国境のないtkinterウィジェット

ttk.Style().configure("TCombobox", padding=4, relief="flat",borderwidth = 
0,shiftrelief = 0) 

などのようなものを試しましたが、何も境界線を削除していないようです。私は行方不明のものがありますか?理想的には、たとえば、「ボタン」は、この非常にフレームの上のボタンのように見えます。透明な背景と境界線を持たないシンボルだけです。

+0

ttkの代わりにtkinterのボタンを使ってみましたか? –

+0

tkinterにはコンボボックスがないので、私はそれを考慮していませんでした。すべてのtkinter(ttkではない)ウィジェットを「平坦化」(境界線なし、救済なしなど)できますか?たぶん、私はコンボボックスの問題を回避することができます。 – user3486991

+0

tkinterとttkの両方のウィジェットを同じアプリケーションで使用できます。一般的に言えば、tkinterウィジェットはttkウィジェットよりも(あるいは少なくとも、より簡単に設定できる)はるかに設定可能です。 –

答えて

0

ボタンの非動的画像を追加しますButton-1クリック(mouse-press)のevent.x属性とevent.y属性をチェックします。これらの座標を使用して、ユーザーが「ボタン」をクリックしたかどうかを判断します。

+0

ありがとう、私はもっと「ネイティブ」なソリューションを望んでいました。しかし、それは少なくともボタンのために働くだろう。コンボボックスなどは別の話かもしれません。 – user3486991

0

このスクリプトは、あなたがそれを子要素ごとにレイアウトをループし、レイアウト情報とするためのオプションを返す、指定されたスタイルのためにそう

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のより悪いに見える見つけますバージョン

関連する問題