更改 xpnative 主题中 ttk.Progressbar 元素的颜色 - python [英] changing colour of ttk.Progressbar elements in the xpnative theme - python

查看:61
本文介绍了更改 xpnative 主题中 ttk.Progressbar 元素的颜色 - python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 python 2.7 和 TK 制作一个 gui,它访问文本文件并使用其中的数据来做很多事情,但这里相关的是发送一条 gchat 消息.目前,我一切正常,我需要帮助的一点是当我调用我的模块发送消息时,消息发送得很好,尽管我希望用户知道正在发生的过程,所以我创建了一个 ttk.进度条.但我想对此进行一些改进:

I'm using python 2.7 and TK to make a gui which accesses text files and uses data in them to do many things, but the one relevant here is sending a gchat message. Currently, I have everything working, the point I need some help with is when I call my module to send the message, the message is sent perfectly, although I wanted the user to have an indication of the process happening, so I created a ttk.progressbar. but there is a few things I'd like to improve on this:

1) 我想改变实际栏的外观,在查看源文件时,我看不到任何选项,当我用谷歌搜索问题时,我能找到的唯一解决方法是更改​​源代码,我很确定这只会在运行我的文件时改变它,然后当用户运行它时,这将是标准?最好,我希望栏是透明的,虽然蓝色可以工作,但我看到有些人在窗口机器中将蓝色作为状态,窗口是我的主要关注点,所以如果我可以说,窗口中的蓝色,但是其他地方的本地人,那没问题.

1) I would like to change the appearance of the actual bar, upon viewing the source files, I couldn't see any options, and when I googled the problem the only fix I could find was to change the source code, I'm pretty sure this would only change it when ran with my files, then when the user runs it, it would be the standard? preferably, I'd like the bar to be transparent, although blue would work, I've seen some people having blue as a state in window machines, windows is my main concern, so if I could get say, blue in windows, but native elsewhere, that would be fine.

2)希望这个更简单一点,但是当按下按钮时,它会从用户输入中获取值,这些值仍然可以更改,可能会改变函数的结果,无论如何要停止对 tk 的所有输入窗口,然后在功能完成后恢复?

2)this one is hopefully a bit more simple, but when the button is pressed it takes values from user input which can still be changed, maybe altering the outcome of the function, is there anyway to stop all input to a tk window, then resume when the function is complete?

以下是我目前的情况,感谢您的帮助

below is what I have so far, thank you for the help

            self.progressbar = ttk.Progressbar(self.gcTableButtonsFrame, length = 70, orient=HORIZONTAL, mode ='determinate')
            self.progressbar.grid(column = 0, row = 0, sticky = 'n s')

            #we then pass through the extension and the string 'test' through this fnction from the gchat module which will then send a 
            #gchat message to the extension passed through
            self.bytes = 0
            self.maxbytes = 0
            self.start()
            self.t = thread.start_new_thread(gchat.sendGChatMessage,(text, "test"))
        except IndexError:
            tkMessageBox.showinfo("Invalid Entry", "Please first select an Entry to send to")

def start(self):
    self.progressbar["value"] = 0
    self.maxbytes = 50000
    self.progressbar["maximum"] = 50000
    self.read_bytes()

def read_bytes(self):
    '''simulate reading 500 bytes; update progress bar'''
    selection2 = self.gcTable.selection()
    self.bytes += 700
    self.progressbar["value"] = self.bytes
    if self.bytes < self.maxbytes:
            # read more bytes after 100 ms
        Tk.after(self.mainPyWindow, 100, self.read_bytes)
    else:
        tkMessageBox.showinfo("Message Sent", "A GChat message has been sent to " + self.gcTable.item(selection2, 'values')[1])
        self.progressbar.destroy()

推荐答案

你的第一个问题有点模棱两可,因为我不确定你是在谈论控制进度条的外观还是进度条的性质正在显示.

Your first question is somewhat ambiguous, in that I'm not sure whether you are talking about controlling the look of the progress bar or the nature of the progress it is displaying.

进度条的性质是通过它的值和它的 mode 选项来控制的(determinate 进度条不同于 indeterminate ;前者是通过value控制的,后者只是表明某事正在发生").

The nature of the progress bar is controlled via its value and its mode option (determinate progress bars are different from indeterminate ones; the former are controlled via the value, the latter just show that "something is happening").

进度条的外观由整体主题控制.在 Windows 和 Mac OS X 上,默认主题是系统主题,这意味着进度条看起来是原生的,无论是什么.我最近没有在 Linux 上尝试过主题,所以我忘记了它们在那里的样子;切换主题:

The look of a progress bar is controlled by the overall theme. On Windows and Mac OS X, the default theme is the system theme meaning that the progress bar will look native, whatever that is. I've not experimented recently with themes on Linux so I forget what they look like there; switch themes with:

# Switch to the included 'clam' theme
s = ttk.Style()
s.theme_use('clam')

这篇关于更改 xpnative 主题中 ttk.Progressbar 元素的颜色 - python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆