How to bind mouse action over multiple entry widgets Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!How to add placeholder to an Entry in tkinter?Passing Entry widget input to binding/event handler functionHow to return multiple values from a function?Accessing Entry widget information: tkinter pythonPython Tkinter - Overwriting/Deleting “Default” Widget BindingsHow to iterate over rows in a DataFrame in Pandas?grid_remove on an Entry widgetVisible textvariable in tkinter Entry widgetPython - function arguments not workingPython tkinter Canvas root.after() maximum recursion depth exceededHow to trigger tkinter's “<Enter>” event with mouse down?

What do you call the main part of a joke?

Amount of permutations on an NxNxN Rubik's Cube

Central Vacuuming: Is it worth it, and how does it compare to normal vacuuming?

Does the Mueller report show a conspiracy between Russia and the Trump Campaign?

Intuitive explanation of the rank-nullity theorem

Draw 4 of the same figure in the same tikzpicture

Did any compiler fully use 80-bit floating point?

1-probability to calculate two events in a row

What order were files/directories output in dir?

Girl Hackers - Logic Puzzle

What would you call this weird metallic apparatus that allows you to lift people?

Can the Flaming Sphere spell be rammed into multiple Tiny creatures that are in the same 5-foot square?

Dyck paths with extra diagonals from valleys (Laser construction)

What does 丫 mean? 丫是什么意思?

How do living politicians protect their readily obtainable signatures from misuse?

How many time has Arya actually used Needle?

How would a mousetrap for use in space work?

Is it possible for SQL statements to execute concurrently within a single session in SQL Server?

What is the difference between a "ranged attack" and a "ranged weapon attack"?

Did Mueller's report provide an evidentiary basis for the claim of Russian govt election interference via social media?

How were pictures turned from film to a big picture in a picture frame before digital scanning?

How many morphisms from 1 to 1+1 can there be?

What initially awakened the Balrog?

Strange behavior of Object.defineProperty() in JavaScript



How to bind mouse action over multiple entry widgets



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!How to add placeholder to an Entry in tkinter?Passing Entry widget input to binding/event handler functionHow to return multiple values from a function?Accessing Entry widget information: tkinter pythonPython Tkinter - Overwriting/Deleting “Default” Widget BindingsHow to iterate over rows in a DataFrame in Pandas?grid_remove on an Entry widgetVisible textvariable in tkinter Entry widgetPython - function arguments not workingPython tkinter Canvas root.after() maximum recursion depth exceededHow to trigger tkinter's “<Enter>” event with mouse down?



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I'm able to bind a mouse action on a single entry widget, meaning, by default a value will be present in the entry box, if i click then the default will be removed. How would i do the same when loop is used over individual boxes. If i click on any entry box, the default value must be removed



from tkinter import *

root = Tk()

def hello(event):
ent.delete(0, END)

for x in range(4):
ent=Entry(root,fg="grey")
ent.insert(0, "dd/mm/yy")
ent.pack()

ent.bind('<Button-1>',hello)

root.minsize(400, 400)
root.mainloop()









share|improve this question
























  • So are you asking how to call the same callback on all entries when one of them is clicked upon? or are you asking how to bind the same command to multiple different entries

    – Joshua Nixon
    Mar 22 at 11:08











  • same command to different entries over the loop

    – Nalini V
    Mar 22 at 11:14











  • Check out this solution and also this one.

    – fhdrsdg
    Mar 22 at 11:14












  • i edited the code where am seeing the change only in the last box irrespective of where i click

    – Nalini V
    Mar 22 at 11:30











  • That's because at the end of the loop, ent is the last entry widget. You could replace ent.delete(0, END) with event.widget.delete(0, END), but I'd recommend you take a look at the two answers I linked, they make a class inherited from Entry with this functionality added, which makes this a lot easier.

    – fhdrsdg
    Mar 22 at 11:35

















0















I'm able to bind a mouse action on a single entry widget, meaning, by default a value will be present in the entry box, if i click then the default will be removed. How would i do the same when loop is used over individual boxes. If i click on any entry box, the default value must be removed



from tkinter import *

root = Tk()

def hello(event):
ent.delete(0, END)

for x in range(4):
ent=Entry(root,fg="grey")
ent.insert(0, "dd/mm/yy")
ent.pack()

ent.bind('<Button-1>',hello)

root.minsize(400, 400)
root.mainloop()









share|improve this question
























  • So are you asking how to call the same callback on all entries when one of them is clicked upon? or are you asking how to bind the same command to multiple different entries

    – Joshua Nixon
    Mar 22 at 11:08











  • same command to different entries over the loop

    – Nalini V
    Mar 22 at 11:14











  • Check out this solution and also this one.

    – fhdrsdg
    Mar 22 at 11:14












  • i edited the code where am seeing the change only in the last box irrespective of where i click

    – Nalini V
    Mar 22 at 11:30











  • That's because at the end of the loop, ent is the last entry widget. You could replace ent.delete(0, END) with event.widget.delete(0, END), but I'd recommend you take a look at the two answers I linked, they make a class inherited from Entry with this functionality added, which makes this a lot easier.

    – fhdrsdg
    Mar 22 at 11:35













0












0








0








I'm able to bind a mouse action on a single entry widget, meaning, by default a value will be present in the entry box, if i click then the default will be removed. How would i do the same when loop is used over individual boxes. If i click on any entry box, the default value must be removed



from tkinter import *

root = Tk()

def hello(event):
ent.delete(0, END)

for x in range(4):
ent=Entry(root,fg="grey")
ent.insert(0, "dd/mm/yy")
ent.pack()

ent.bind('<Button-1>',hello)

root.minsize(400, 400)
root.mainloop()









share|improve this question
















I'm able to bind a mouse action on a single entry widget, meaning, by default a value will be present in the entry box, if i click then the default will be removed. How would i do the same when loop is used over individual boxes. If i click on any entry box, the default value must be removed



from tkinter import *

root = Tk()

def hello(event):
ent.delete(0, END)

for x in range(4):
ent=Entry(root,fg="grey")
ent.insert(0, "dd/mm/yy")
ent.pack()

ent.bind('<Button-1>',hello)

root.minsize(400, 400)
root.mainloop()






python tkinter






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 22 at 11:29







Nalini V

















asked Mar 22 at 11:02









Nalini VNalini V

83




83












  • So are you asking how to call the same callback on all entries when one of them is clicked upon? or are you asking how to bind the same command to multiple different entries

    – Joshua Nixon
    Mar 22 at 11:08











  • same command to different entries over the loop

    – Nalini V
    Mar 22 at 11:14











  • Check out this solution and also this one.

    – fhdrsdg
    Mar 22 at 11:14












  • i edited the code where am seeing the change only in the last box irrespective of where i click

    – Nalini V
    Mar 22 at 11:30











  • That's because at the end of the loop, ent is the last entry widget. You could replace ent.delete(0, END) with event.widget.delete(0, END), but I'd recommend you take a look at the two answers I linked, they make a class inherited from Entry with this functionality added, which makes this a lot easier.

    – fhdrsdg
    Mar 22 at 11:35

















  • So are you asking how to call the same callback on all entries when one of them is clicked upon? or are you asking how to bind the same command to multiple different entries

    – Joshua Nixon
    Mar 22 at 11:08











  • same command to different entries over the loop

    – Nalini V
    Mar 22 at 11:14











  • Check out this solution and also this one.

    – fhdrsdg
    Mar 22 at 11:14












  • i edited the code where am seeing the change only in the last box irrespective of where i click

    – Nalini V
    Mar 22 at 11:30











  • That's because at the end of the loop, ent is the last entry widget. You could replace ent.delete(0, END) with event.widget.delete(0, END), but I'd recommend you take a look at the two answers I linked, they make a class inherited from Entry with this functionality added, which makes this a lot easier.

    – fhdrsdg
    Mar 22 at 11:35
















So are you asking how to call the same callback on all entries when one of them is clicked upon? or are you asking how to bind the same command to multiple different entries

– Joshua Nixon
Mar 22 at 11:08





So are you asking how to call the same callback on all entries when one of them is clicked upon? or are you asking how to bind the same command to multiple different entries

– Joshua Nixon
Mar 22 at 11:08













same command to different entries over the loop

– Nalini V
Mar 22 at 11:14





same command to different entries over the loop

– Nalini V
Mar 22 at 11:14













Check out this solution and also this one.

– fhdrsdg
Mar 22 at 11:14






Check out this solution and also this one.

– fhdrsdg
Mar 22 at 11:14














i edited the code where am seeing the change only in the last box irrespective of where i click

– Nalini V
Mar 22 at 11:30





i edited the code where am seeing the change only in the last box irrespective of where i click

– Nalini V
Mar 22 at 11:30













That's because at the end of the loop, ent is the last entry widget. You could replace ent.delete(0, END) with event.widget.delete(0, END), but I'd recommend you take a look at the two answers I linked, they make a class inherited from Entry with this functionality added, which makes this a lot easier.

– fhdrsdg
Mar 22 at 11:35





That's because at the end of the loop, ent is the last entry widget. You could replace ent.delete(0, END) with event.widget.delete(0, END), but I'd recommend you take a look at the two answers I linked, they make a class inherited from Entry with this functionality added, which makes this a lot easier.

– fhdrsdg
Mar 22 at 11:35












1 Answer
1






active

oldest

votes


















0














Your problem is that you're hardcoding ent in your callback. The event object tells you which widget received the event, so use that instead.



def hello(event):
event.widget.delete(0, END)





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55298219%2fhow-to-bind-mouse-action-over-multiple-entry-widgets%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Your problem is that you're hardcoding ent in your callback. The event object tells you which widget received the event, so use that instead.



    def hello(event):
    event.widget.delete(0, END)





    share|improve this answer



























      0














      Your problem is that you're hardcoding ent in your callback. The event object tells you which widget received the event, so use that instead.



      def hello(event):
      event.widget.delete(0, END)





      share|improve this answer

























        0












        0








        0







        Your problem is that you're hardcoding ent in your callback. The event object tells you which widget received the event, so use that instead.



        def hello(event):
        event.widget.delete(0, END)





        share|improve this answer













        Your problem is that you're hardcoding ent in your callback. The event object tells you which widget received the event, so use that instead.



        def hello(event):
        event.widget.delete(0, END)






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 22 at 12:32









        Bryan OakleyBryan Oakley

        223k22279440




        223k22279440





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55298219%2fhow-to-bind-mouse-action-over-multiple-entry-widgets%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript