How do I check if a Checkbutton is checked? - python

I have created a list of 20 check buttons for my last application using Tkinter, but I can't figure out the way to check if a Checkbutton is or not checked.
How do I check if a Checkbutton is checked?

Take a look at this answer: Making Menu options with Checkbutton in Tkinter?
For each of the menu item, you need to create and associate a tk.BooleanVar() that matches the status of the checkbox.
Since you have a lot of check buttons, you might want to create a list or dictionary to store these BooleanVars and associate each of them with its own Checkbutton.

Related

Python tkinter - rename a treeview item

I am making a user interface with tkinter's treeview and one thing that I want to be able to do with it is to allow the user the ability to change the names displayed by the items whenever they want. However, from what I can tell from the documentation, the function that could do this, set only allows for column values to be changed.
Is there any way to change the text of a treeview item without deleting it and remaking it?

Balloon box with optionmenu in tkinter (python)

I am creating a GUI that contains a drop-down box (called an optionmenu in tkinter). I have it populated with entries.
This is what I want to do but can't figure out the proper commands. If a user hovers their mouse over a specific entry in the option menu, I want a hoverbox/balloon box/tooltip (whatever you want to call it) to appear and show a description of the option they are hovering over.
I assume I have to use some sort of event but I am not sure. Does anyone know how?

Selecting and deselecting tkinter Menu Checkbutton widgets

I have a checkbutton inside of a menu widget in python with tkinter. (Using python 3.5.2). I know that with normal checkbuttons you can select or deselect the checkbuttons using checkbutton.select() and checkbutton.deselect(). I need to know how to do this with the checkbuttons that I have in the menu object.
I have tried the menu.entrybutton.configure(id, coption) method but there is no coption for selecting and deselecting checkbuttons within the menu.
Any help would be appreciated.
You should assign an IntVar (or possibly StringVar) to the checkbutton when you create it, via its variable= configuration option. You call .get() on this var to check the button's state, and .set() to change its state.

Doubts about checking if button is already displayed and making a list of radio buttons

I have two questions regarding tkinter that I cant seem to find the answer too.
1) I currently have 2 radio buttons. I have programmed them in such a way that when one of them is clicked another definition is called and that creates a regular button on the screen. Now my problem is, if the user toggles between the both radio buttons, each time a new button will be created (instead of just having 1 the first time he toggles the options). Is there any way I can stop the extra buttons from being created if one already exsists?
2) Is there a widget that can easily be used to create check box lists?
EDIT: Sorry, I meant check box list not radio button list.
1> Define you button outside the eventHandler of the radiobutton.
inside the event handler only grid/pack it,whenever the radiobutton is pressed. In this way the button will not be defined multiple times.
N.B. Use fix row & column with the grid if you need.

How can I tell if the drop-down list of a `ComboBox` is open?

In wxPython, how can I tell what is the state of the drop-down list of a ComboBox, that is, is it open or closed?
I'm trying to implement a ComboBox that allows the user to delete a value from the list by opening the drop-down list, selecting an item, and pressing delete (Edit: when I say selecting here I mean just highlighting an item, without clicking it yet, so the drop-down list remains open).
I can bind the delete key, and I know how to delete an item, the only problem is the delete key has a different function if the drop-down list is closed (its usual function in the text field), which I want to preserve.
Use EVT_COMBOBOX. That fires when the user selects something from the list. I would store the selection in an instance variable (like self.currentSelection). You may want to store the previous selection too. Then when the user presses "delete" you can delete the new selection or show a prompt asking them if they really want to delete that item.
UPDATE: As mentioned in the comments, I think ComboCtrl is a good alternative. You can find examples of its usage at the following:
The wxPython demo package
http://xoomer.virgilio.it/infinity77/wxPython/combo/wx.combo.ComboCtrl.html
http://robsworldoftech.blogspot.com/2010/02/wxpython-example-for-wxcomboctrl-with.html

Categories