tk

Why is the creation order of widgets important?

做~自己de王妃 提交于 2019-12-08 16:14:31
The following code works fine. It displays a panedwindow , with a blue box on top and a green box below: panedwindow .root -orient vertical -showhandle true -background red frame .top -background blue -width 100 -height 100 frame .bot -background green -width 100 -height 100 .root add .top .bot pack .root -expand true -fill both However, when I move the panedwindow command down, things stop working. The top, blue box is not shown. Instead, the red of the panedwindow itself shines through: frame .top -background blue -width 100 -height 100 panedwindow .root -orient vertical -showhandle true

Get the text of a treeview item using it's Id - Treeview Tkinter

泪湿孤枕 提交于 2019-12-08 05:46:08
问题 I would like to get the display text of the treeview item subdir3 when I double click. I know 'text' is not correct as print tree.set('subdir3') prints a dictionary of columns and values and text is not part of that, but I can't find anything about it in the limited documentation I have found. Here's my code: from Tkinter import * import ttk root = Tk() def OnDoubleClick(event): print tree.set('subdir3')['text'] tree = ttk.Treeview(root) tree["columns"]=("one","two") tree.heading("one", text=

Showing Tkinter window larger than desktop

早过忘川 提交于 2019-12-07 22:59:04
问题 I need to show Tkinter window, which I create with Tk(), to be larger than desktop, and moved to some coordinates outside the desktop. Unfortunately when I do: root = tk.Tk() root.geometry("%dx%d+%d+%d", (10000, 10000, -300, -300)) then this window shows up, but maximized on desktop. When I show the window at first, and resize/move later, then everything is OK, but I don't want to see the small empty window at the beginning. How can I show the window with the coordinates and size at the very

题解 [51nod1340]地铁环线

☆樱花仙子☆ 提交于 2019-12-07 22:37:39
题解 [51nod1340]地铁环线 题面 解析 本文参考这篇博客 一开始看到只有120行就打算写一写, 结果一刚就是三个星期 摆摆摆 本来是当查分约束入门学的. step 1 首先来考虑下如果已知总长度 \(s\) 如何判断是否合法. 显然差分约束 对于 \(dis(x,y)>=w\) 这个式子等价于 \(dis[x]+w<=dis[y]\) , 即 \(dis[y]+(-w)>=dis[x]\) . 因此, 若 \(x<y\) ,则 \(y\) 向 \(x\) 连一条边权为 \(-w\) 的边. 若 \(x>y\) ,则 \(y\) 向 \(x\) 连一条边权为 \(s-w\) 的边(要绕一圈,yy一下就知道了). 对于 \(dis(x,y)<=w\) 这个式子就是 \(dis[x]+w>=dis[y]\) . 若 \(x<y\) ,则 \(x\) 向 \(y\) 连一条边权为 \(w\) 的边. 若 \(x>y\) ,则 \(x\) 向 \(y\) 连一条边权为 \(s+w\) 的边. 又因为边权至少为 \(1\) ,即 \(dis[x]+1<=dis[y]\) . \(dis[y]+(-1)>=dis[x]\) . 因此 \(i+1\) 要向 \(i\) 连一条边权为 \(-1\) 的边(n-1要特判) 最后,跑n-1边Bellman_Ford, 若还能进行松弛操作

How to view a menu when a button is pressed?

那年仲夏 提交于 2019-12-07 22:32:40
问题 Following up on this question, I am trying to view (same as in when clicked with left mouse button) a menu, sub1 , when a button, Test , is pressed, but I can't. In the following code button seems to instead freeze the GUI: import tkinter as tk root = tk.Tk() menubar = tk.Menu(root) sub1 = tk.Menu(menubar, tearoff=0) sub1.add_command(label="Item 1", command=lambda : print("item 1")) sub1.add_command(label="Item 2", command=lambda : print("item 2")) menubar.add_cascade(menu=sub1, label="Sub1",

Padding specified in style ignored by Ttk Frame

不羁岁月 提交于 2019-12-07 10:03:51
问题 The following code works as expected, presenting a red background button (with lots of padding) in a green background frame (also with lots of padding). Note that Frame padding is specified both in the Style statement and the ttk.Frame initialization. import ttk import Tkinter root = Tkinter.Tk() ttk.Style().configure("TFrame", background="#0c0", padding=60) ttk.Style().configure("TButton", background="#c00", padding=20) frame = ttk.Frame(root, padding=60) frame.pack() btn = ttk.Button(frame,

How can I match background colors for a Frame in a Notebook for ttk/Tkinter on a Mac?

懵懂的女人 提交于 2019-12-07 09:39:49
问题 While working on a Tkinter + ttk based GUI on my Mac, I noticed a problem with background colors and the Notebook widget. When adding a ttk.Frame as a ttk.Notebook tab, the displayed background of the frame does not match the 'inset' background for the notebook tab. How can I make the ttk.Frame match the surrounding background color, without hard-coding a value that will look weird for non-Mac users? I read a few SO answers suggesting custom styles, but it's unclear how to query for the

How to view a menu when a button is pressed?

徘徊边缘 提交于 2019-12-06 13:56:49
Following up on this question , I am trying to view (same as in when clicked with left mouse button) a menu, sub1 , when a button, Test , is pressed, but I can't. In the following code button seems to instead freeze the GUI: import tkinter as tk root = tk.Tk() menubar = tk.Menu(root) sub1 = tk.Menu(menubar, tearoff=0) sub1.add_command(label="Item 1", command=lambda : print("item 1")) sub1.add_command(label="Item 2", command=lambda : print("item 2")) menubar.add_cascade(menu=sub1, label="Sub1", underline=0) root.config(menu=menubar) def cb(*args): root.tk.call('::tk::TraverseToMenu', root, 'S')

How to implement a button whose functionality is a cross between radiobutton and checkbutton?

点点圈 提交于 2019-12-06 13:29:29
问题 I want to dynamically disable or enable checkbutton s based on the options the user selects. What I would like is a cross between radiobutton and checkbutton . checkbutton .c1 -text "C1" -variable c1 checkbutton .c2 -text "C2" -variable c2 checkbutton .c3 -text "C3" -variable c3 checkbutton .c4 -text "C4" -variable c4 grid .c1 -sticky w grid .c2 -sticky w grid .c3 -sticky w grid .c4 -sticky w In the above example, if I check C1 , then the options C2 and C4 should be grayed out. Similarly, if

Missing tk.h and tcl.h files when building VRip

妖精的绣舞 提交于 2019-12-06 12:07:18
问题 I am trying to compile VRip in Ubuntu 10.04, using the site http://graphics.stanford.edu/software/vrip/guide/ as a guide. It relies on installation of Tcl and Tk -- I have acquired the latest versions of these from the synaptic package manager. When I write "make depend", I get the error: In file included from vripInit.cc:30: vripInit.h:22:17: error: tcl.h: No such file or directory vripMain.cc:22:16: error: tk.h: No such file or directory In file included from vripMain.cc:28: vripInit.h:22