changing colour of ttk.Progressbar elements in the

2019-02-26 19:07发布

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) 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)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()

1条回答
混吃等死
2楼-- · 2019-02-26 19:43

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.

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”).

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')
查看更多
登录 后发表回答