tkinter

How to put variable into a label text?

…衆ロ難τιáo~ 提交于 2021-02-04 21:56:29
问题 I wrote a tkinter code, with a label. There was a variable in the label text. lab = Label(root, text = 'randomstrings', x, 'randomstrings') lab.pack() When I ran the code, it gave an error message here: , x, It said: positional argument follows keyword argument 回答1: You must put all label pieces together before passing them to the Label : Label(root, text = 'randomstrings' + str(x) + 'randomstrings', ...) or: Label(root, text = 'randomstrings{}randomstring'.format(x), ...) 回答2: Using commas

bind python measure() takes exactly positional argument

我只是一个虾纸丫 提交于 2021-02-04 21:29:47
问题 I have made a simple GUI in python using Tkinter. I've written it so that when a button is pressed a function (measure) is called. I'm now trying to bind the Enter key to also carry out this function using: root.bind("<Return>", measure) This gives the error when Enter is pressed: TypeError: measure() takes no arguments (1 given) A quick search tells me that if I give the function the argument (self) then the enter bind will work, however if I do this then the button widget gives the error:

tkinter keeping window on top all times on MacOS

北城以北 提交于 2021-02-04 21:24:00
问题 I'm trying to create a screen "curtain" which blocks parts of the screen except for the mouse cursor's vicinity. On windows, using root.wm_attributes("-topmost", "true") keeps the window on top, even if I focus on another app, perfectly. However, upon running the code on MacOS, if the focus for the window is lost, it will not keep itself on topmost. What would be the MacOS equivalent to -topmost window manager attribute which will always keep the window on top, regardless of focus? import

tkinter keeping window on top all times on MacOS

房东的猫 提交于 2021-02-04 21:22:56
问题 I'm trying to create a screen "curtain" which blocks parts of the screen except for the mouse cursor's vicinity. On windows, using root.wm_attributes("-topmost", "true") keeps the window on top, even if I focus on another app, perfectly. However, upon running the code on MacOS, if the focus for the window is lost, it will not keep itself on topmost. What would be the MacOS equivalent to -topmost window manager attribute which will always keep the window on top, regardless of focus? import

Global hotkey on windows with tkinter

為{幸葍}努か 提交于 2021-02-04 21:11:39
问题 I want a python tkinter application to register a global hotkey (triggered even if the application has not the focus). I've found some pieces, but I can't find a way to put them together... Basically, I can register the hotkey (with a call to the windows API RegisterHotKey), but it send a "WM_HOTKEY" message to the root windows that is under Tkinter mainloop management, and I cant find a way to bind on it... tk.protocol() function seems to be there for it, but this message seems not to be

Python Tkinter: How to config a button that was generated in a loop?

一世执手 提交于 2021-02-04 21:09:30
问题 I am using Python 2.7 and Tkinter to make a GUI for my code. At one point, a frame is filled with many buttons in a loop. When I click on one of the buttons, the function needs to know from where it was called, so I googled and found out this nice way to do it: def generate_buttons(n): for i in xrange(n): newbutton = str(i) newbutton = Button(myFrame, text=newbutton, command= lambda name=i:print_name(name)).grid(column=i) and: def print_name(name): print name So when I generate my buttons

Tkinter right-click popup unresponsive on OSX

心不动则不痛 提交于 2021-02-04 19:50:06
问题 I have been looking for a way to display a right-click popup menu on OSX. So far all of my attempts have been unsuccessful. The same code will work fine on a Linux VM(Ubuntu). For arguments sake I copied the code written in these two pages and tried to run them on my machine. tkinter app adding a right click context menu? http://effbot.org/zone/tkinter-popup-menu.htm Neither have worked in the way I expect them to on OSX but they do when I run them on an Ubuntu VM. The machine I am using is a

How to align text to the right in ttk Treeview widget?

元气小坏坏 提交于 2021-02-04 18:13:45
问题 I am using a ttk.Treeview widget to display a list of Arabic books . Arabic is a right-to-left language, so the text should be aligned to the right. The justify option that is available for Label and other ttk widgets does not seem to work for Treeview . Does anyone know how to do this? 回答1: The ttk.Treeview widget has an anchor option you can set for each column. To set the anchor of a column to the right side use: ttk.Treeview.column(column_id, anchor=Tkinter.E) 回答2: In addition to the

How to change background color in ttk.Combobox's listview?

≡放荡痞女 提交于 2021-02-04 13:51:25
问题 How can I change the style of the combobox's listview? Here is part of the code so far: style = ttk.Style() style.configure("BW.TLabel", foreground="black", background="#20252b", insertbackground="white", fieldbackground= 'blue') optmn = ttk.Combobox(self, style="BW.TLabel") optmn.place(x=140, y=200, width=150, height=25) How can I access the style of the listview of the combobox? Sample Image: 回答1: Found it! the way to change the BG of the listview of the combobox is: import ttk import

Function callback in event binding, w/ and w/o parentheses

﹥>﹥吖頭↗ 提交于 2021-02-04 08:41:27
问题 I just started with my first Python program and ran into a pretty strange issue with function callback. Here is the code that matches my expectation: from tkinter import * def say_hello(): print('hello') root = Tk() Button(root, text='say hello', command=say_hello).pack() root.mainloop() Now if I add parentheses to the function name Button(root, text='say hello', command=say_hello()).pack() 'hello' will be printed only once when the program starts, but nothing further happens when the button