简体   繁体   English

一个TTKTheme在app风格中的应用

[英]An application of TTKTheme to the app style

I have installed the ttk themes through pip install ttkthemes, import and apply theme 'blue' in labels, entries and buttons, however, the app style did not apply the selected theme.我已经通过 pip 安装了 ttk 主题安装 ttkthemes,在标签、条目和按钮中导入并应用主题“蓝色”,但是,应用程序样式没有应用所选主题。 Following is my py file.以下是我的 py 文件。

import requests
from tkinter import *
from tkinter import ttk
from ttkthemes import ThemedTk

root = ThemedTk(theme='blue')
root.title('Currency Converter')
root.geometry("450x400")

style = ttk.Style()
style.theme_use('blue')  
                       
def currency_convertion():
    global result_label
    url = "https://api.apilayer.com/exchangerates_data/convert?to=" + to_currency_entry.get() + "&from=" + from_currency_entry.get() + "&amount=" + amount_entry.get()

    payload = {}
    headers= {
    "apikey": ""
    }

    response = requests.request("GET", url, headers=headers, data = payload)

    status_code = response.status_code
    data = response.text
   
    result_label = ttk.Label(label_frame, text=f'{to_currency_entry.get()} {data[231:240]}', font='Helvetica, 25',bd=0, bg='#292929', fg='silver')
    result_label.grid(row=5, column= 0, columnspan=2)
    
    
def clear_result_label():
    result_label.config(text=f'', font='Helvetica, 25',bd=0, bg='#292929', fg='silver')
    from_currency_entry.delete(0, END)
    to_currency_entry.delete(0, END)
    amount_entry.delete(0, END)
    
frame = Frame(master=root, width=200, height=300)
frame.pack(padx=20, pady=20)

label_frame = Frame(master=root, width=350, height=300)
label_frame.pack(pady=10)

from_currency_label = ttk.Label(frame, text='From Currency')
from_currency_label.grid(row=1, column=0, pady=10)

to_currency_label = ttk.Label(frame, text='To Currency')
to_currency_label.grid(row=2, column=0, pady=10)
 
amount_label = ttk.Label(frame, text='Amount')
amount_label.grid(row=3, column=0, pady=10)

from_currency_entry = ttk.Entry(frame, font="Helvetica, 15")
from_currency_entry.grid(row=1, column=1, stick=W+E+N+S, pady=10)

to_currency_entry = ttk.Entry(frame, font="Helvetica, 15")
to_currency_entry.grid(row=2, column=1, stick=W+E+N+S,pady=10)
 
amount_entry = ttk.Entry(frame, font="Helvetica, 15")
amount_entry.grid(row=3, column=1, stick=W+E+N+S, pady=10)

button = ttk.Button(frame, text="Convert", command=currency_convertion)
button.grid(row=4, column=0, pady=20, padx=35)

button = ttk.Button(frame, text="Clear", command=clear_result_label)
button.grid(row=4, column=1, pady=20)

root.mainloop()

Would each theme need to install individually?每个主题都需要单独安装吗? or change the themes only the way to change the style.theme_use that will affect every widget?或仅更改主题以更改将影响每个小部件的 style.theme_use 的方式? How could I apply the select theme to the app style?如何将 select 主题应用于应用程序样式?

I tried your code and below is the resulting theme.我试过你的代码,下面是结果主题。 I think it has worked, especially when comparing it to the non-themed UI under that.我认为它已经奏效了,尤其是在将其与非主题 UI 进行比较时。 I know that I don't pose an answer but I thought I'd just let you know that your theme works on my computer(linux).我知道我没有给出答案,但我想我只是让您知道您的主题适用于我的计算机(linux)。 Maybe try reinstalling ttkthemes?也许尝试重新安装 ttkthemes?

生成的用户界面

没有主题界面

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM