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?
Related
Widget "visit" (tab key) order is determined by the order of widget creation. Is there a simple, pure Python (3.x) way to force the widgets to be visited in a different, user-determined order? If not, is there a simple "Tk" way of doing this? (BTW, This is about about widgets, not notebook tabs).
I couldn't find anything about how to do this while researching the usual tkinter sites, on stackoverflow etc. Have I missed something basic, a widget parameter, universal method, etc.?
Example of why this ability is needed:
The python code (an application/package/class) uses several different widget types and implemented as several files. The definition/creation of all widgets of the same type, e.g. checkboxes, are placed (isolated) inside their own file (e.g. there is a Checkbox file, a Notebook file, a Button File, etc). At initialization this organization causes all occurances of one widget type to be created (and thus tab-ordered) sequentially - and before/after any widgets of any other type.
The resulting widget "visit" order is not (from the users viewpoint) the natural order. How can I force the natural order without resorting to changing the order of widget creation (or doing somethlng as kludgey/artificial as placing every widget in it's own frame and then arranging the frame creation order to match the natural order)?
I am new to designing GUIs in python and have a query:
Is there a way to have a label or any other widget with copyable text. I want to provide help section within GUI which will contain a sample xml to be given as input, I want user to be able to copy that xml.
I don't want that information to go away if user cuts that information, so I am not using a entry widget with pre-filled data.
Is there a way to achieve this?
Thanks!
Use a text widget in disabled state.
There is no insertion cursor in this state, but the text may still be selected and copied (but not modified).
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
My GUI consists of a wx.ListCtrl on the left, with a list of objects to edit, and a set of wx.TextCtrls on the right, for editing the selected object.
My strategy for implementing this was:
On a textbox's wx.EVT_KILL_FOCUS , update the relevant attribute of the currently selected object
On the list's wx.EVT_LIST_ITEM_DESELECTED, either hide the textboxes or blank them out and disable them (needed for when the user clicks the blank space in the list control)
On the list's wx.EVT_LIST_ITEM_SELECTED, populate the text controls with the values of the selected object's attributes
With this setup, there are 3 use cases, and 2 of them work:
When the user is clicking/tabbing between textboxes, the correct wx.EVT_KILL_FOCUSs occur, and the attributes get updated.
When the user clicks from a textbox into the blank space in the list, that's OK as well: first wx.EVT_KILL_FOCUS causes the attribute to update, and then wx.EVT_LIST_ITEM_DESELECTED hides the textboxes.
The problem is when the user clicks directly from a textbox to another object in the list control. The order of events in this case is wx.EVT_LIST_ITEM_DESELECTED, wx.EVT_LIST_ITEM_SELECTED, and then finally wx.EVT_KILL_FOCUS. You can probably see the problem: by the time the method that updates attributes is called, a new object has already been selected and the textboxes have been populated with new values.
So I know exactly what the problem is, but I can't come up with a nice, clean way to fix it. Ideally I'd like to be able to change the order of the wx events (putting wx.EVT_KILL_FOCUS at the front), but I doubt that's possible. Is there some other obvious solution I'm missing?
wx.EVT_LIST_ITEM_DESELECTED will only fire when the user changes the selected object in the list box. This serves the same purpose as losing focus on the text box. Call the update routines from that event as well. To skip the subsequent wx.EVT_KILL_FOCUS from the text box set a "isDirty" attribute in the parent object after you update the attributes. You can check the isDirty value anytime to confirm there are changes to commit. This attribute would have to be reset when you populate the text boxes for the new selection and then set during other textbox events.
It looks to me like you are trying to re-implement from scratch the functionality of wxListbook. It seems like a lot of work, perhaps you can use wxListbook
to do what you need.
http://docs.wxwidgets.org/2.9.4/classwx_listbook.html
I want to provide a listbox where the user can select (multiple) characters (usually close to 15). Quite often some of these will be sequenced, so a listbox is easier than a validated text entry field.
Since the character combination has a meaning to the user, it is user friendly to orient the listbox horizontally.
Is there an easy way e.g. a theme, setting or subclass of the Tkinter listbox so I do not have to build my own?
No, there is no setting, subclass or theme that will let you do that with a listbox.
What you might want to use instead is a set of check buttons with the indicator turned off so they each appear as a button with a single letter. You can then pack them all horizontally in a frame. With the indicator off, the button will appear sunken when selected, or normal otherwise.