bpo-42305: Added Auto_Complete DropBox Suggestion For Tkinter#23210
bpo-42305: Added Auto_Complete DropBox Suggestion For Tkinter#23210RajvirSingh1313 wants to merge 15 commits intopython:mainfrom
Conversation
|
@alex,@rhettinger,@vstinner,@serhiy-storchaka,@corona10 |
|
@RajvirSingh1313 I hope to do at least an initial review of your PR in the coming days, but in the meantime please add "bpo-42305: " to the start of the PR title (this will resolve bedevere/issue-number) and also read the devguide on adding news entries. |
|
Please also note that by signing the CLA you agree that the PSF can relicense your work without the needing to include a copy of MIT licence found on the original repo. |
|
Thanks @E-Paine |
Keep a copy of what you have as we will probably want something similar for the docs. |
|
@E-Paine So means I should edit the rst file ? |
|
@E-Paine I am new to this so thats why I am doing alot of things wrong. |
|
@RajvirSingh1313 that's absolutely fine (I've not been here that long either ;-) Don't try writing some docs yet as I would like to review your code first and will try and explain what needs to happen then. |
|
@E-Paine I am going to rewrite the rst file I will write the code of the auto_complete.py in it |
|
@E-Paine Please stay here till it got correct because I need guidance. |
|
@E-Paine I had changed the rst file content with source code of auto_complete.py |
|
The news file will be compiled with all the other news files into a final webpage. The description should be short and describe briefly the new feature (if a user is interested, they can go look at the docs - see the Python 3.9 whatsnew for examples) |
|
@E-Paine Can you write rst ?? |
|
For me because I had no idea. |
|
|
|
@E-Paine Is this will work? And this is in rst and this comment is for markdown so there will be different in appearance. Tkinter AutocompleteText autocompletion provides relevant real-time results to users. Structure NOTE: These examples will only run under Python 3. To make them Python 2-compatible, replace To add a new autocompletion frame to our interface, first initialize .. code:: python Now you need to configure the instance by passing it an iterable .. code:: python You can pass additional arguments to
Let's play around with these arguments: .. code:: python NOTE: You may call the With that out of the way, you can display .. code:: python |
|
@E-Paine Sir as the suggestions you had given are very nice. I had marked the problems Resolved which you had suggested and I am confused about the Unresolved problems so please tell me how to solve them. This my email - rajvirsinghdeol1313@gmail.com. |
|
@RajvirSingh1313 I have made a note of your email address (you may wish to delete/edit your comment as this is a publicly available conversation). I will try to keep our conversation on Github as much as possible and will add clarification to my comments when I have time. Please do not ping more than once as I am either A) busy or B) asleep (you are several timezones ahead of me). |
@E-Paine Please clarify these points and please add the code line which have error or need improvement. |
The reason these were not comments like the others is that these are more generic points rather than relating to a particular place in the code.
This is what I attempted to do with the longer explanations but will start by trying to rephrase the ttk suggestion (also addressing the point above about how this cannot be a comment for a specific line of code). I will also work on clarifying the issues not marked as resolved. If you look towards the bottom of the ttk module (Lib/tkinter/ttk.py - line 1506 onwards) you will find the implementation of two widgets which are implemented in Python and built using other widgets. I propose that you move the entire content of Lib/tkinter/auto_complete.py to become a new ttk widget (so as to avoid adding new module unnecessarily and making it confusing/fragmented for the user). The new auto_complete.py file could then be removed. The reason this couldn't be commented on a line of code is because this applies to the entire auto_complete.py file. Does this make more sense? |
|
@E-Paine Thanks, Now please tell me to what to do now. So orderwise I can do and the it will be easy for both of us. I think first I should try to add auto_complete to ttk file. |
|
Hey I am trying to add auto_complete to ttk but I don't know how to do. But I got a idea what if we add auto_complete to ttk entry wiget please tell me how to add it because I din't worked with modules and it is too complicated to work with modules I had only one year experience in python. And you have alot experience in python so please help me. |
|
Please do not touch |
|
@E-Paine Sorry for late I was gone somewhere for some days and I had not taken laptop with me. So thats why I had done nothing on this project. But now I am home, So I can work now. |
|
Can you please give me example of code that will have auto_complete entry in ttk file ? |
|
I am not quite sure I understand the question but the result should be something where you can do |
|
This PR is stale because it has been open for 30 days with no activity. |
Updating the repo
|
Please Someone help me to make this Pull request succesful. |
|
@boakley, Dear Sir, It would be very helpful for me. |
|
Sorry, I don't know any of the core tkinter developers.
…On Fri, Apr 23, 2021 at 2:07 AM Rajvir Singh ***@***.***> wrote:
@boakley <https://github.com/boakley>, Dear Sir,
I am a big fan of you because you have helped the community a lot by
explaining the problems and giving solutions to that problems. I have made
a pr about Tkinter dropbox I thought it would be great to have it in core
Tkinter so I made this pull request but I am very immature to handle this
pr myself so it would be great for me if you guide me and talk to the core
python devs so they can merge this pr.
It would be very helpful for me.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#23210 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAISMYXSSNQUIDX2VMTIYA3TKEMBVANCNFSM4TPU2K2A>
.
|
|
Oh no problem, But can you review my code and can see if it is correctly
written.
On Sat, Apr 24, 2021 at 3:04 AM Bryan Oakley ***@***.***>
wrote:
… Sorry, I don't know any of the core tkinter developers.
On Fri, Apr 23, 2021 at 2:07 AM Rajvir Singh ***@***.***>
wrote:
> @boakley <https://github.com/boakley>, Dear Sir,
> I am a big fan of you because you have helped the community a lot by
> explaining the problems and giving solutions to that problems. I have
made
> a pr about Tkinter dropbox I thought it would be great to have it in core
> Tkinter so I made this pull request but I am very immature to handle this
> pr myself so it would be great for me if you guide me and talk to the
core
> python devs so they can merge this pr.
>
> It would be very helpful for me.
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <#23210 (comment)>,
or
> unsubscribe
> <
https://github.com/notifications/unsubscribe-auth/AAISMYXSSNQUIDX2VMTIYA3TKEMBVANCNFSM4TPU2K2A
>
> .
>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#23210 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/APDS745NJFEYTUK2PSN6RNDTKHRV7ANCNFSM4TPU2K2A>
.
|
|
This has what I would consider a couple of fatal flaws: First, it calls Second, it doesn't appear to be possible to use the keyboard to get an autocomplete value. It seems that I must use the mouse to pick an item. For this to be a viable widget I think it must support using the keyboard to select a value from the list. Note: if you switch to using a |
|
I am very happy that you had given your time for code review and I am very
graceful to you about this advice and I will try to make sure to
remove those flaws and make this feature more reliable. But there is one
thing I like to share with you that My name is Rajvir Singh, I am from
Punjab, India and I am 14 years old so I am not really that much pro in
python core dev. I always wanted to talk to you and I didn't really
introduce myself in my first message so I thought I should in this message.
Thanks for your advice and I will work on it to improve it.
…On Mon, Apr 26, 2021 at 9:58 PM Bryan Oakley ***@***.***> wrote:
This has what I would consider a couple of fatal flaws:
First, it calls grid to add the listbox to the window, potentially
causing the entire UI to resize. Instead, it needs to use a Toplevel
window so that it doesn't affect the geometry of the application.
Second, it doesn't appear to be possible to use the keyboard to get an
autocomplete value. It seems that I must use the mouse to pick an item. For
this to be a viable widget I think it must support using the keyboard to
select a value from the list.
Note: if you switch to using a Toplevel for the dropdown, you no longer
need to inherit from a frame. Instead, you can inherit from an entry widget
and you'll get all of the normal configuration options for free.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#23210 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/APDS744HVP4Y57NIM6EWSNTTKWIBZANCNFSM4TPU2K2A>
.
|
|
And I think I will need your help with the first point that I should switch from using the |
|
While I'm still interested in adding this, I fear there could be major problems, most notably performance on larger lists. To achieve reasonable performance, we would possibly want to use a Radix tree (or something similar) which 1. would not belong in tkinter 2. I doubt people would want elsewhere in the stdlib. |
I am happy that you are still interested in this, so if you can help me that would be great. Because I made this pr for just adding this feature to the Tkinter I don't know hardcore python in very depth. This code was written by @coal0 so I contacted him with the flaws and told him that I am making a pull request with his code but he didn't reply so I am stuck in a situation where I can't do anything with this code. so please help me if you know how to fix it. |
This is a problem because that means you do not own the copyright. By committing this, we would be relicensing it and we cannot do that without his written permission. |
|
He has a repo and it is under MIT license
…On Sun, May 9, 2021 at 2:13 PM E-Paine ***@***.***> wrote:
This code was written by coal0
This is a problem because that means you do not own the copyright. By
committing this, we would be relicensing it and we cannot do that without
his written permission.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#23210 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/APDS742UUEFPGUSOQHK3X4LTMZDKTANCNFSM4TPU2K2A>
.
|
That is the problem. The MIT license requires that:
We cannot fulfil this and would therefore need an exemption from it. |
|
So should I close this PR?
…On Mon, May 10, 2021 at 1:03 AM E-Paine ***@***.***> wrote:
it is under MIT license
That is the problem. The MIT license requires that:
The above copyright notice and this permission notice shall be included in
all
copies or substantial portions of the Software. Utilities/LICENSE
<https://github.com/coal0/Utilities/blob/master/LICENSE#L12-L13>
We cannot fulfil this and would therefore need an exemption from it.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#23210 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/APDS742GL73QE2PMC4XHKFDTM3PPNANCNFSM4TPU2K2A>
.
|
|
And thanks for the clarification you are really helped me a lot!
On Mon, May 10, 2021 at 9:01 AM Rajvir Singh ***@***.***>
wrote:
… So should I close this PR?
On Mon, May 10, 2021 at 1:03 AM E-Paine ***@***.***> wrote:
> it is under MIT license
>
> That is the problem. The MIT license requires that:
>
> The above copyright notice and this permission notice shall be included
> in all
> copies or substantial portions of the Software. Utilities/LICENSE
> <https://github.com/coal0/Utilities/blob/master/LICENSE#L12-L13>
>
> We cannot fulfil this and would therefore need an exemption from it.
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <#23210 (comment)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/APDS742GL73QE2PMC4XHKFDTM3PPNANCNFSM4TPU2K2A>
> .
>
|
Unfortunately, yes please. If you write your own implementation, I would be happy to take a look at it (I might write my own when I have time). Sorry it ended like this and I hope you have more success with future patches. |
|
Thanks, I am gonna close this PR but can you give your own email or discord
id so we can talk about making this widget together
…On Mon, May 10, 2021 at 2:44 PM E-Paine ***@***.***> wrote:
So should I close this PR?
Unfortunately, yes please. If you write your own implementation, I would
be happy to take a look at it (I might write my own when I have time).
Sorry it ended like this and I hope you have more success with future
patches.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#23210 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/APDS747RKTFYVKGNAF6SG23TM6PWPANCNFSM4TPU2K2A>
.
|


This is auto complete drop box suggestion wiget for tkinter
Tkinter Autocomplete
Text autocompletion provides relevant real-time results to users. Because tkinter does not provide a widget for adding autocompletion to GUIs out of the box, I decided to make one myself. This utility is compatible with and has been tested on Python 2.7.1 and Python 3.6.0.
Structure
NOTE: The
Tkinterlibrary for Python 2 andtkinterlibrary for Python 3 will from now on be referred to astk.The
AutocompleteEntryclass (which can be found here)derives from
tk.Frameand is a container used to group atk.Entryandtk.Listboxwidget. Should you need to modify the widgets,they can be accessed as (respectively)
AutocompleteEntrysentryandlistboxattributes.The entry widget acts like a normal textbox. When activated, it binds
<KeyRelease>to a private method which will updatethe list of suggestions. The listbox widget contains the suggestions themselves. When activated, it binds
<<ListboxSelect>>to aprivate method which sets the entry widget to whatever value was selected.
Since an instance of
AutocompleteEntryis atk.Frameinstance too, you can place it by calling itspackorgridmethods withtheir respective arguments.
Quickstart
NOTE: These examples will only run under Python 3. To make them Python 2-compatible, replace
tkinterwithTkinter.To add a new autocompletion frame to our interface, first initialize one:
Now you need to configure the instance by passing it an iterable containing all autocompletion entries.
Do this by calling its
buildmethod:You can pass additional arguments to
build:max_entries(integer):The maximum number of entries to display at once. This value directly corresponds to the listbox widget's
heightattribute. Defaults to5.case_sensitive(boolean):If
True, only autocomplete entries that enforce the same capitalization as the current entry will be displayed.If
False, all autocomplete entries that match with the current entry will be displayed.Defaults to
False.no_results_message(string orNone):The message to display if no suggestions could be found for the current entry.
This argument may include a formatting identifier (
{}) which, at runtime, gets formatted as the current entry. IfNoneis specified, the listbox will instead be hidden until the next<KeyRelease>event.Let's play around with these arguments:
NOTE: You may call the
buildmethod multiple times on an instance ofAutocompleteEntry, to dynamically change the available suggestions.With that out of the way, you can display
entry:Now, each time a user presses a key while the entry widget has focus, a list of suggestions will display below it.
Additional options
By default, the
tk.Listboxwidget has a width of25pixels and a height of5(items). Thetk.Entrywidget also has a default width of25pixels. These settings can be modified through the following class attributes:auto_complete.AutocompleteEntry.LISTBOX_HEIGHT: The height to specify when creating thetk.Listboxwidget. There's no need to modify this, since the maximum number of entries to be displayed can be passed as an argument tobuild.auto_complete.AutocompleteEntry.LISTBOX_WIDTH: The width to specify when creating thetk.Listboxwidget. Any positive integer is valid.auto_complete.AutocompleteEntry.ENTRY_WIDTH: The width to specify when creating thetk.Entrywidget. Any positive integer is valid.NOTE: You almost always want to keep the 1:1
LISTBOX_WIDTH:ENTRY_WIDTHratio.You can retrieve the current entry by accessing the instance's
textattribute (which is atk.StringVarinstance):To further customize the entry widget, you may set its font options, for example:
Or to change the background color for the listbox widget:
This the demo
This the repo here
https://bugs.python.org/issue42305