ttk

Default window colour Tkinter and hex colour codes

时光怂恿深爱的人放手 提交于 2019-12-18 20:10:24
问题 I would like to know the default window colour in Tkinter when you simply create a window: root = Tk() If there is one, it is possible to set widgets to the same colour or use a hex colour code? (using rgb) The colour code I have found for the 'normal' window is: R = 240, G = 240, B = 237 Thanks. 回答1: Not sure exactly what you're looking for, but will this work? import Tkinter mycolor = '#%02x%02x%02x' % (64, 204, 208) # set your favourite rgb color mycolor2 = '#40E0D0' # or use hex if you

Tkinter: How to set ttk.Radiobutton activated and get its value?

怎甘沉沦 提交于 2019-12-18 16:47:46
问题 1) I need to set one of my three ttk.Radiobuttons activated by default when I start my gui app. How do I do it? 2) I also need to check if one of my ttk.Radiobuttons was activated/clicked by the user. How do I do it? rb1 = ttk.Radiobutton(self.frame, text='5', variable=self.my_var, value=5) rb2 = ttk.Radiobutton(self.frame, text='10', variable=self.my_var, value=10) rb3 = ttk.Radiobutton(self.frame, text='15', variable=self.my_var, value=15) self.rb1.grid(row=0) self.rb2.grid(row=1) self.rb3

Simple ttk ComboBox demo

旧街凉风 提交于 2019-12-18 11:32:09
问题 This should be very simple but I am really struggling to get it right. All I need is a simple ttk ComboBox which updates a variable on change of selection. In the example below, I need the value of value_of_combo variable to be updated automatically every time a new selection is made. from Tkinter import * import ttk class App: value_of_combo = 'X' def __init__(self, parent): self.parent = parent self.combo() def combo(self): self.box_value = StringVar() self.box = ttk.Combobox(self.parent,

Python3: How to dynamically resize button text in tkinter/ttk?

旧街凉风 提交于 2019-12-18 09:06:16
问题 I want to know how to arrange for the text on a ttk widget (a label or button, say) to resize automatically. Changing the size of the text is easy, it is just a matter of changing the font in the style. However, hooking it into changes in the size of the window is a little more tricky. Looking on the web I found some hints, but there was nowhere a complete answer was posted. So, here below is a complete working example posted as an answer to my own question. I hope someone finds it useful. If

ttk Treeview selection_set can't accept spaces

与世无争的帅哥 提交于 2019-12-18 08:52:34
问题 I'm building a gui using tkk in python and I'm having trouble with the Treeview command selection_set() . I'm trying to use it to set the default selection when my program starts but it seems that it can't accept a string with spaces in it. tree.selection_set("Sunset Grill") Causes: return self.tk.call(self._w, "selection", selop, items) _tkinter.TclError: Item Sunset not found Can anyone give any suggestions? 回答1: You might try the following: tree.selection_set('"Sunset Grill"') I'm guessing

Default text as well as list textvariable Entry widget Tkinter

半世苍凉 提交于 2019-12-18 06:57:43
问题 I have the following Entry box where due to obtaining values I have put a list option in for textvariable. However I was wondering if it would be possible to put a default text in the background so to show which values are required in each box (like a greyscale text, 'Value 1, value 2 etc..). self.numbers = [StringVar() for i in xrange(self.number_boxes) ] #Name available in global scope. box=Entry(self.frame_table,bg='white',borderwidth=0, width=10, justify="center", textvariable=self

How to make ttk.Treeview's rows editable?

南笙酒味 提交于 2019-12-17 19:25:09
问题 Is there any way to use ttk Treeview with editable rows? I mean it should work more like a table. For example on double click on the item make the #0 column 'editable'. If this isn't possible, any way to allow mouse selecting on the item would be just fine. I haven't found any mention of this in tkdocs or other documents. 回答1: After long research I haven't found such feature so I guess there's any. Tk is very simple interface, which allows programmer to build 'high-level' features from the

How to change ttk.progressBar color in python

好久不见. 提交于 2019-12-17 19:25:08
问题 Does anyone know how I can change the color of my ttk.progressBar? It now shows a green color, and I would love to have it blue. import ttk self.progressBar = ttk.Progressbar(frame3, length=560, maximum=100, mode='determinate'); self.progressBar.place(x=-5, y=60) 回答1: you can change the color of a progressbar, but it is tricky. First, you need to understand that if you use the default theme, which is the default theme if you do not specify a theme in the tk.style. Then it will pass all the

ttk.Button returns None

南楼画角 提交于 2019-12-17 14:53:42
问题 I am trying to use the invoke method of a ttk.Button, as shown at TkDocs (look at "The Command Callback" ), but I keep getting this error: AttributeError: 'NoneType' object has no attribute 'invoke' So, I tried this in the Interactive Shell: ActivePython 3.1.1.2 (ActiveState Software Inc.) based on Python 3.1.1 (r311:74480, Aug 17 2009, 12:30:13) [MSC v.1500 32 bit (Intel)] on win32 >>> from tkinter import * >>> import tkinter.ttk as ttk >>> root = Tk() >>> button = ttk.Button(root, text=

Tkinter insert a Combobox inside a Treeview widget

[亡魂溺海] 提交于 2019-12-17 14:21:47
问题 For example, lets create a Treeview widget using a class as follows: class FiltersTree: def __init__(self, master, filters): self.master = master self.filters = filters self.treeFrame = Frame(self.master) self.treeFrame.pack() self._create_treeview() self._populate_root() def _create_treeview(self): self.dataCols = ['filter', 'attribute'] self.tree = ttk.Treeview(self.master, columns = self.dataCols, displaycolumns = '#all') Populate root, insert children as usual. At the end of the codeblock