ttk

Changing the appearance of a Scrollbar in tkinter (using ttk styles)

耗尽温柔 提交于 2019-11-30 09:09:43
I was wondering if you could help me with a style options issue in ttk. I've managed to change most of the basic ttk widgets to the style of my preference. I'm only stuck at changing the style of a scrollbar. I've searched for hours looking for an answer, unfortunately to no avail. Here's a sample code using the scrollbar style option: import tkinter as tk from tkinter import ttk class Gui: def __init__(self,mainframe): #set the style style = ttk.Style() style.configure('Horizontal.TScrollbar',background = "blue" ) #Create a mainframe self.mainframe = mainframe self.mainframe.title("example")

Simple ttk ComboBox demo

混江龙づ霸主 提交于 2019-11-30 03:55:51
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, textvariable=self.box_value) self.box['values'] = ('X', 'Y', 'Z') self.box.current(0) self.box.grid

How to change the color of ttk button

不问归期 提交于 2019-11-30 03:09:26
问题 I am using Python 3.x on Windows. My problem is I want to customize a button widget of ttk by completely changing its background and foreground color. But so far, I have been unsuccessful. My desired button is: I read the ttk.Style guide and used their code: ttk.Style().configure("TButton", padding=6, relief="flat", background="#000") btn = ttk.Button(text="Sample") btn.pack() But it's changing the border color instead of the whole button bakground. Here is the output: Kindly help me achieve

tkinter optionmenu first option vanishes

时间秒杀一切 提交于 2019-11-30 02:05:00
A ttk optionmenu widget starts out with all of its values in the dropdown. Upon selecting any value, the first value in the list vanishes, never to reappear... Does anyone know why? Is this a feature of the widget's design? Try it with the following: import tkinter.ttk as ttk import tkinter as tk a = tk.Tk() options = ['1', '2', '3'] value = tk.StringVar() masterframe = ttk.Frame() masterframe.pack() dropdown = ttk.OptionMenu(masterframe, value, *options) dropdown.pack() a.mainloop() Note - another user asked the same question here: OptionMenu won't show the first option when clicked (Tkinter)

Set a default value for a ttk Combobox

守給你的承諾、 提交于 2019-11-29 18:17:15
问题 I'm using Python 3.2.1 in Arch Linux x86_64. This one is really driving me crazy: I just want to have a default, preselected value for a ttk.Combobox as soon as I grid it. This is my code: from tkinter import Tk, StringVar, ttk root = Tk() def combo(parent): value = StringVar() box = ttk.Combobox(parent, textvariable=value, state='readonly') box['values'] = ('A', 'B', 'C') box.current(0) box.grid(column=0, row=0) combo(root) root.mainloop() Which draws an empty Combobox . What's funny is that

Tkinter Entry not showing the current value of textvariable

回眸只為那壹抹淺笑 提交于 2019-11-29 15:54:13
Consider this code: from tkinter import * from tkinter.ttk import * tk=Tk() def sub(): var=StringVar(value='default value') def f(): pass Entry(tk,textvariable=var).pack() Button(tk,text='OK',command=f).pack() sub() mainloop() We expect the value of var appears in the entry, but actually it doesn't. The weird thing is that if I put the statement var.get() in the callback function of the button, the value of var will apear. Is that a bug caused by some kind of local variable optimization in Python? And what can I do to make sure that the value of textvariable will always appear in the entry?

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

牧云@^-^@ 提交于 2019-11-29 15:06:17
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 anyone has further improvements to suggest, I will be delighted to see them! The example below shows

Removing Ttk Notebook Tab Dashed Line

a 夏天 提交于 2019-11-29 14:43:28
I'm trying to make a tkinter app that doesn't look like a tkinter app. I'm using a ttk Notebook, and the tabs have this little dotted line around the text when they're selected. It looks terrible, and I can't find a way to remove it using either styles or config. Here's a screenshot to clarify: Edit for code (I don't think it'll be terribly helpful, since I'm actually just trying to remove a default style thing.): Here is the notebook creation: tabs = ttk.Notebook(mainframe, width=319, height=210, style=style.Notebook) tabs.grid(column=0, row=1, sticky=('n', 'w', 'e', 's')) tabs

ttk Treeview selection_set can't accept spaces

拟墨画扇 提交于 2019-11-29 14:42:13
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? You might try the following: tree.selection_set('"Sunset Grill"') I'm guessing this based on the code for ttk.py and my limited understanding of Tcl. The call to tree.selection_set()

Changing ttk Button Height in Python

◇◆丶佛笑我妖孽 提交于 2019-11-29 14:06:23
问题 This seems like a silly question, but is it possible to change the height of a ttk button manually? Something like button = tkinter.Button(frame, text='hi', width=20, height=20...) works just fine for a tkinter button. Though I'd prefer to use a ttk button since it looks much better aesthetically. button = ttk.Button(frame, text='hi', width=20, height=20...) does not work, height doesn't seem to be a valid option. I've tried setting it with config or looking for elements in the style to