2015-11-23 73 views
2

在我的電腦用Win8.1,當我用下面的代碼TTK主題不工作,只是老式的Tkinter

from tkinter import * 
    from tkinter.ttk import * 

    Tk().mainloop() 

我只看到老看Tkinter的。任何想法如何解決它?

enter image description here

我試圖用不同的主題沒有結果。

出於某種原因,下面的代碼:

from tkinter import * 
from tkinter.ttk import * 

Style().theme_use("alt") 
Tk().mainloop() 

結果有兩個相同的Tkinter的老式窗戶,似乎並沒有被正確的。

PS:這似乎是與Win8.1相關的問題,在這裏看到: Python 2.7 - ttk module seemingly not working in Windows 8.1

但我沒有發現任何信息,如何解決它。任何消息都會受到歡迎。 :)

EDIT1: 嘗試下面的代碼片段後:

from tkinter import * 
from tkinter.ttk import * 
from functools import partial 

root = Tk() 
style = Style(root) 

def change(name, style): 
    style.theme_use(name) 

for s in style.theme_names(): 
    lb = Button(root, text=s, command=partial(change, s, style)) 
    lb.pack() 

我可以說的主題是不斷變化的不僅是顏色,但是完全。令我困惑的是,我無法看到我期望看到的漂亮花式圖案。 我試圖改變我的Windows設置的性能或視覺方面,但它不是它不工作的原因。

如果您有Win 8.1,您是否按預期工作tkk?

EDIT2: 這是使用例如我的目光從 http://www.tkdocs.com/tutorial/firstexample.html (Win7和Win8.1)

​​

+0

我不認爲ttk影響根窗口,只有裏面的小部件。 –

+0

謝謝,但即使從此源複製的代碼: http://www.tkdocs.com/tutorial/firstexample.html tkinter不能正常工作,如圖所示。和往常一樣老式的主題。 –

+0

當然,使用「alt」主題會帶來不好的結果。如果你沒有明確設置主題並創建一個ttk按鈕,按鈕看起來是否正確? –

回答

-2

嘗試使用from tkinter import ttk和使用ttk.添加新部件時,它可能只是一個範圍問題。

例如:button=ttk.Button(text='hello')

+0

謝謝你,不工作。 –

2

的差異可以很容易地看到這些主題之間的ubuntu。 所以,也許這是win8.1的一個問題。考慮使用ttkthemes模塊? ttkthemes模塊是另一組更「時髦」的風格。 要安裝:

sudo apt-get install python3-tk 
sudo -H pip3 install ttkthemes 

想了解更多,請訪問: https://github.com/RedFantom/ttkthemes/wiki/Usage

我已經回答了另一個類似的問題,你可以通過這個鏈接引用它: How to make pyinstaller import the ttk theme? 還是讓我在評論中知道,如果這也是行不通的。