This is a minor issue but I've been struggling with it most of the afternoon and getting nowhere, so here goes. I'm about to write a Python script that will require the use of the ScrolledListBox(). Never having used it before, I started with an experimental script where I could play with it and get familiar with it. I now have the script to where I can double click on an item and, in the handler, correctly print the selected item to stdout. However, I notice that when the item is selected, either with a single or double click, a rectangular border appears around the item in the list and remains there until another item is selected. I've been trying to see if there's a way to get rid of this border but so far have been unable to do so. Here's what I've tried:
1) Thanks to another post in this forum I found that the keys() method would give me a list of the available options for the widget. So, given a ScrolledListBox named slb1 I could do something like print(slb1.keys()) and I got the full list of everything I could configure on the widget. One of them was 'selectborderwidth' so I did: slb1.configure(selectborderwidth=0) thinking that this would remove the border. It didn't.
2) Next I dug through my copy of "Python and Tkinter" and discovered the selection_clear(first, last=None) method. The description states, "If any of the elements between first and last (inclusive) are selected, they are deselected." So I tried: slb1.selection_clear(0, None) in the handler but once again the rectangular border around the item remained.
I'm just getting started in Python and Tkinter so hopefully I'm missing something somebody with more experience knows about. Any ideas on how to get rid of the border?
Thanks,
Dave
The documentation by New Mexico Tech, which can be a good reference when working with Tkinter, lists the attributes for the Listbox widget, among which activestyle. This parameter refers to the box around the currently active (not necessarily selected) item, and can take the values underline, dotbox, and none.
If you set activestyle to none, the dotted border will go away.
Related
I'm colorblind and I can barely make out the __init__ when it is on the current line where the caret is, as in this example:
I just can't see it against that highlighted "caret line" background. Same problem for __repr__, __str__, and other such predefined items.
So, I'd like to change their color. How do I do that?
I looked through the color settings (pic below), but I can't figure out which one to change. None of them seem to do what I want.
Yes, I know I could change the color of 'caret row', but that's not a viable alternative, because __init__'s current color also gives me problems in other circumstances.
In PyCharm you can go to File > Settings...
In the settings panel you can go to Editor > Colors and Fonts and select Python.
Now you are given a code sample where __init__ is probably part of. If you click on the __init__ element, PyCharm will redirect you to an element called "Predefined item definition" which you can set to another color (the "Foreground" element in the right panel):
This is a screenshot of Pycharm Community on Ubuntu. I hope this helps.
Your settings panel seems to have a hierarchical view, based on the panel on the right it is probably located under Identifiers > Predefined symbol.
Changing this will change all predefined elements (like __len__, __class__, etc.) but since you say it is because of color blindness, you want probably to change these as well anyway.
I have a problem in which I update StaticText fairly often(once every second) and every time it updates, it tears the frame. This is very bothersome on Windows but on Linux it never happened. I tried doing TextCtrl Readonly but I get ugly boxes around text I was wondering if there was a better option for updating text in wxPython frequently that wouldn't tear the screen. Thanks in advance!
I wish I understood better what you meant by "tearing" the frame - I don't seem to have problems with changing StaticText values after a window is created (though sometimes it's necessary to call Layout on a Panel or Dialog).
However, if you're really just looking for read-only TextCtrl's without the "ugly boxes" you should use TextCtrl(style = wx.NO_BORDER | wx.TE_READONLY). The combination will give you what you want - what appears to be a StaticText, but that can't be user-edited and doesn't display a border. You'll also be able to select its value (which may or may not be an advantage).
I embedded a checkbox in every row of my wx.Grid.
I used this page as an example: wx Python wiki
The problem is, my last checkbox value is never saved and I can't get quite my head around it.
Second problem: Just clicking the Cell and not the checkbox changes the cell value, but not the checkbox. Is there a solution for this? It's possible that the problems are related.
My whole unit can be found here (disregard the readout_main references).
I checked that the 1 or 0 value is really there.
Helping me would mean a lot! Thanks!
Edit2: Solved! I have no idea what changed or why, but now even a RichTextCtrl appends reliably. I left the old message below, despite this.
So I'm writing a GUI in python using wxPython. One of the main elements of this GUI is a textbox.
Features I need:
The ability to reliably append text to the end of the textbox.
Prevent user editing the textbox
Vertical Scroll bar
Features I'd like:
User can select text even when more lines are being appended
Text color can be changed
With that in mind I tried to do use the RichTextCtrl provided by wxPython.
However there appears no way to reliably add text to the end of the text box. The AppendText method is not reliable. If I click a location in the textbox while several lines are being appended this way it is likely one or more of the lines will be inserted where-ever I moved the cursor.
Does anyone have any suggestions on how to reliably append text to a RichTextCtrl? I might be able to clear it and replace all of its text with new text every time I want to append something, but I fear the performance hit from this would be severe. If there is a different text control that would be more appropriate for this please suggest it.
Edit: Using a regular TextCtrl appends reliably. Still no luck with a RichTextCtrl.
AppendText works for me on Windows with wxPython 2.9. If you want to prevent the user from editing, you'll need to use the wx.TE_READ_ONLY style flag. To make a vertical scroll bar appear, add the wx.TE_MULTILINE flag too.
The wxPython demo shows how to change text color. Basically you programmatically select a range and set a style / font for that selection. Getting the ability to select text while appending may not be possible. You would probably have to set up some kind of buffer for the appends and append after the user finishes selecting or keep track of what the user is selecting, append and then reselect.
I am currently using some wxPython's AuiNotebook in one of my projects and I have a problem that can't manage to solve. I think there should be a simple solution but can't manage to find it.
I have created a new class derived from wx.lib.agw.aui.AuiNotebook and I am trying to get the index of a tab at the moment it's clicked. I wrote something like that:
class NewNotebook(wx.lib.agw.aui.AuiNotebook):
# __init__ function an stuff...
def OnTabClicked(self, evt):
index = self.GetSelection()
print index
wx.lib.agw.aui.AuiNotebook.OnTabClicked(self, evt)
The aim was to capture the index of the tab clicked on and in some cases, have a special behavior, or just perform a regular click otherwise. However, I think that AuiNotebook.OnTabClicked actually changes the selection among different things. It would explain why index contains the value of the tab that was selected before the click.
I did not a find a way to get the selection of the new tab though. I looked for some information in the captured event but still could not find the one I wanted.
So, does someone know how I can get the selected tab before I call AuiNotebook.OnTabClicked?
There doesn't seem to be a builtin way to do this. The closest I found was something I helped with on the wxPython mailing list, but that had to do with double-clicking.
Here's one workaround that came to me though. When you first show the frame, set some kind of class property to the currently shown tab (i.e. self.currentTab = 0). Then catch the EVT_AUINOTEBOOK_PAGE_CHANGING or EVT_AUINOTEBOOK_PAGE_CHANGED event and update the property. For me, when I catch EVT_AUINOTEBOOK_PAGE_CHANGING, I always get the index of the tab I'm clicking on, at least on Windows.