4/26/2023 0 Comments Tkinter widget winfo![]() Very handy to be able to make a small test harness for a widget rather You may think you don't want to reuse the child, but it is This has a direct effect on reusability of the child in otherĬontexts. It is not assuming that some incantation on its parent will do the right When you pass a stringVar to the child, it knows only what it is told, StringVar any different than designing with the knowledge that anĪreaCode widget can not exist except as a child of phonenumber? This is not a criticism, but how is passing a known intVar or Java I often set the parent to monitor property change events of the child. HasChanged up when a change occurs, poll the dependent widgets when youĪnother way would be to pass a calllback to the child widget that itĬalls when it is changed, or to set up some kind of event mechanism. One possibility is for the phones.hasChanged to poll the hasChangedĪttributes of its children. Needs to be updated, but since areaCode is a child of phones, If I change the area code in one record only the phonenumber table ![]() OK, I misunderstood your original post on that point. More generally, IMO it is good practice to try to make acyclic dependency graphs between classes and modules, so if the parent depends on the child, the child shouldn't depend on the parent. It makes code harder to understand, harder to test and harder to reuse. It's not that different from relying on any other global state. ![]() And I find that if I design widgets for reuse, other uses tend to come up often enough to make it worth-while. It is much harder to do this if the widget depends on its enclosing environment. You may think you don't want to reuse the child, but it is very handy to be able to make a small test harness for a widget rather than firing up the whole application, navigating to the correct screen, etc. This has a direct effect on reusability of the child in other contexts. When you pass a stringVar to the child, it knows only what it is told, it is not assuming that some incantation on its parent will do the right thing. > IntVar to the child widget and letting it work with that?Ĭan not exist except as a child of phonenumber? > Personally I think it is bad design for a widget to assume anything In Java I often set the parent to monitor property change events of the child. In other words, instead of propagating hasChanged up when a change occurs, poll the dependent widgets when you need to know.Īnother way would be to pass a calllback to the child widget that it calls when it is changed, or to set up some kind of event mechanism. One possibility is for the phones.hasChanged to poll the hasChanged attributes of its children. Pass the state of areaCode (has it changed or not), not its value? This is not a criticism, but how is passing a known intVar or stringVarĪny different than designing with the knowledge that an areaCode widgetĬan not exist except as a child of phonenumber? Besides, I need to Phones.hasChanged needs to be set to True by the areaCode entry widget. To be updated, but since areaCode is a child of phones, If I change the area code in one record only the phonenumber table needs ![]() phones object (data from phonenumber table) basicData object (data from client table) I’m done the exit routine runs each table objects save routine, whichĬhecks hasChanged to see if an update query needs to be run on that table. I haveĭesigned each table class with a hasChanged attribute, initialized toįalse, if a child Entry widget changes I set has changed to True. Will need updating when I’m done, but the address table may not. If I change or add a phone number that db table Each table has an associated python/tkinterĬlass (widget) that displays the fields in a parent widget, and eachįield is a child of the table widget. The editor brings records from each of the various tables together in ,ship to, mail to, etc.), one for the services they subscribe to, etc. (publish, contact, fax,cell, etc), one for various addresses (publish Related tables one for basic info, one for their various phone numbers The overall app is a gui editor for a database made up of several Maybe I should clarify what I am doing and why, so that I can get a IntVar to the child widget and letting it work with that? Personally I think it is bad design for a widget to assume anythingĪbout its enclosing environment. Self.nametowidget(_parent()).has Changed= True I get the widget name using w.winfo_parent(), then i convert the name What I have works, but seems like a long way around the block. I am trying to get & set the properties of a widget's parent widget.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |