From nulla.epistola at web.de Wed Nov 1 07:33:50 2023 From: nulla.epistola at web.de (Sibylle Koczian) Date: Wed, 1 Nov 2023 12:33:50 +0100 Subject: [Tutor] Help with storing a variable In-Reply-To: References: <753023326.1800082.1698752615619.ref@mail.yahoo.com> <753023326.1800082.1698752615619@mail.yahoo.com> Message-ID: Am 01.11.2023 um 02:48 schrieb ThreeBlindQuarks via Tutor: > > NN, > > Your question is wide open with many possible solutions. > > You say you are storing (presumably reading in if a specific EXCEL file exists, and the updating or rewriting it) so clearly the obvious place is the same file. This would allow portability. > > Allen has already suggested a database for all the data as a better alternative but that could require the machine you store it on be known and have the right software. > He specifically mentioned SQLite - and for practice that sounds quite well. Of course for an application with possibly many users of one and the same database it might not be. But tenant-codes (which sound like primary keys in a SQL context) with different prefixes and autoincrementing number parts would need second thoughts. Regards Sibylle From nulla.epistola at web.de Wed Nov 1 07:33:50 2023 From: nulla.epistola at web.de (Sibylle Koczian) Date: Wed, 1 Nov 2023 12:33:50 +0100 Subject: [Tutor] Help with storing a variable In-Reply-To: References: <753023326.1800082.1698752615619.ref@mail.yahoo.com> <753023326.1800082.1698752615619@mail.yahoo.com> Message-ID: Am 01.11.2023 um 02:48 schrieb ThreeBlindQuarks via Tutor: > > NN, > > Your question is wide open with many possible solutions. > > You say you are storing (presumably reading in if a specific EXCEL file exists, and the updating or rewriting it) so clearly the obvious place is the same file. This would allow portability. > > Allen has already suggested a database for all the data as a better alternative but that could require the machine you store it on be known and have the right software. > He specifically mentioned SQLite - and for practice that sounds quite well. Of course for an application with possibly many users of one and the same database it might not be. But tenant-codes (which sound like primary keys in a SQL context) with different prefixes and autoincrementing number parts would need second thoughts. Regards Sibylle From threesomequarks at proton.me Wed Nov 1 11:54:31 2023 From: threesomequarks at proton.me (ThreeBlindQuarks) Date: Wed, 01 Nov 2023 15:54:31 +0000 Subject: [Tutor] Help with storing a variable In-Reply-To: References: <753023326.1800082.1698752615619.ref@mail.yahoo.com> <753023326.1800082.1698752615619@mail.yahoo.com> Message-ID: Just to be clear, Databases are often designed with helpful features if you understand them and use them properly. You can sometimes continue doing things other ways. So if you have a field in a table set to autoincrement, that can be useful but not the only way. You can also have such an incremented numeric field alongside a prefix and or suffix field that you combine into another column or create a joint key. But if you are working from Python or some other programming language, you can simply make a column that is normal and do the calculations yourself. Your program can even read in all entries, split the text to isolate your number, find the biggest one in use, increment that and use that for a new entry you crate and then request your new record be added. Obviously, that is not the best way for larger amounts of data. An alternative is to create ANOTHER table in which you store the name of a variable alongside the next (or current) sequence number. You can then query that table to get the next available and after using it, store the new number in the table. Obviously when many applications/users may be using the same data at once, many new concerns arise including locking access and race conditions and balancing resources. At some point, a database designed for this is even more of a good choice. But as noted, for simpler uses, Python has oodles of ways to do things such as pickle and many others. Some let you create sections in a data file containing various kinds of data. Some store it in JSON format. Many methods allow you to store a data structure that contains both the rows/columns you want to save as well as additional parts like a variable containing the sequence number all at once. Many such methods are perfectly fine for small uses like a startup file containing a few options. Having to rewrite large amounts in such a file regularly when just an update of one record is needed or when multiple processes are updating, is not a great choice. So use what makes sense for the needs but don't make it more complex if the needs are met more simply. Sent with Proton Mail secure email. ------- Original Message ------- On Wednesday, November 1st, 2023 at 7:33 AM, Sibylle Koczian wrote: > Am 01.11.2023 um 02:48 schrieb ThreeBlindQuarks via Tutor: > > > NN, > > > > Your question is wide open with many possible solutions. > > > > You say you are storing (presumably reading in if a specific EXCEL file exists, and the updating or rewriting it) so clearly the obvious place is the same file. This would allow portability. > > > > Allen has already suggested a database for all the data as a better alternative but that could require the machine you store it on be known and have the right software. > > He specifically mentioned SQLite - and for practice that sounds quite > well. Of course for an application with possibly many users of one and > the same database it might not be. > > But tenant-codes (which sound like primary keys in a SQL context) with > different prefixes and autoincrementing number parts would need second > thoughts. > > Regards > Sibylle > > > _______________________________________________ > Tutor maillist - Tutor at python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor From ibrahimsikander97 at gmail.com Tue Nov 7 11:24:22 2023 From: ibrahimsikander97 at gmail.com (Ibrahim Sikander) Date: Tue, 7 Nov 2023 21:24:22 +0500 Subject: [Tutor] Python Message-ID: I want to learn Python Sent from [1]Mail for Windows References Visible links 1. https://go.microsoft.com/fwlink/?LinkId=550986 From PythonList at DancesWithMice.info Tue Nov 7 14:57:40 2023 From: PythonList at DancesWithMice.info (dn) Date: Wed, 8 Nov 2023 08:57:40 +1300 Subject: [Tutor] =?utf-8?q?Clearing_the_Deque_=E2=80=A2_Picturing_Python?= =?utf-8?b?4oCZcyBgZGVxdWVgIGRhdGEgc3RydWN0dXJl?= Message-ID: <5d0fd65d-d1ab-412c-bf69-2c9d13cef879@DancesWithMice.info> You will be welcome to join us at our next (hybrid) meeting: Wednesday, 15 November 2023, 1815~2030 NZDT (0515~0730 UTC). How often do you use a deque*? ?Not very? is a common answer. Perhaps you?ve never used it. In this presentation, Stephen won?t try to convince you to use it more often. Instead, he?ll present a different perspective on what this data structure is, and how it differs from a list. The presentation will compare deques and lists in a visual manner, to help us understand why we may need a deque in certain situations. We?ll also explore some demonstration examples to highlight the differences in performance between the two data structures in different scenarios. *pronounced like ?deck" Audience: This presentation is ideal for those who have either never heard of deque, or have heard of it but never really used it or understood why it?s needed. The more experienced may find the visual story insightful. Stephen used to be a physicist, which is where he learned programming. After working in science and academia for over a decade, he decided to escape before it was too late. Since then, has focused exclusively on teaching coding and communicating about Python. A big part of his day is busy with running Codetoday?we teach Python coding to children between 7 and 16 years old (https://www.codetoday.co.uk/). He also runs courses for adults and corporate training programs, and particularly, writing about Python. He writes the articles he wished he had when learning. He publishes articles at The Python Coding Stack (https://thepythoncodingstack.substack.com/) and also wrote an online book (soon to be in other formats, too) for beginners, The Python Coding Book (https://thepythoncodingbook.com/). Please RSVP on Meetup.com (NZPUG Auckland Branch): https://www.meetup.com/nzpug-auckland/events/295433874/ -- Regards, =dn From alan.gauld at yahoo.co.uk Tue Nov 7 20:16:12 2023 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Wed, 8 Nov 2023 01:16:12 +0000 Subject: [Tutor] Python In-Reply-To: References: Message-ID: On 07/11/2023 16:24, Ibrahim Sikander wrote: > I want to learn Python Great, we are here to help. Some extra information will help: 1) Have you programmed before in another language(if so which ones?) 2) What OS are you using (Windows given your email said Mail for Windows, but which version? 3) What do you aim to do with Python? Do you have a project in mind? (That may influence your choice of tutorials and tools.) Also, do you prefer to learn by doing(ie typing a lot of code) or by understanding principles(ie reading a lot before typing a lot) The python.org website has a 'getting started' section with pages for programmers and non-programmers. Each one has a list of appropriate tutorials. Try a few, find one that suits your taste and ask questions here. When doing so remind us of your Python version and OS. If reporting an error include the full error message and the associated code in the email(not a screenshot!) The more information you give the more likely we are to give a useful answer. Saying "it doesn't work" is not helpful. Tell us what you expected and what you got. (ideally cut 'n paste!) -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos From mats at wichmann.us Wed Nov 8 12:08:15 2023 From: mats at wichmann.us (Mats Wichmann) Date: Wed, 8 Nov 2023 10:08:15 -0700 Subject: [Tutor] =?utf-8?q?Clearing_the_Deque_=E2=80=A2_Picturing_Python?= =?utf-8?b?4oCZcyBgZGVxdWVgIGRhdGEgc3RydWN0dXJl?= In-Reply-To: <5d0fd65d-d1ab-412c-bf69-2c9d13cef879@DancesWithMice.info> References: <5d0fd65d-d1ab-412c-bf69-2c9d13cef879@DancesWithMice.info> Message-ID: <2d1a00f6-f71a-4c57-8ab0-ccccb58da6c8@wichmann.us> On 11/7/23 12:57, dn via Tutor wrote: > You will be welcome to join us at our next (hybrid) meeting: Wednesday, > 15 November 2023, 1815~2030 NZDT (0515~0730 UTC). > > > How often do you use a deque*? ?Not very? is a common answer. Perhaps > you?ve never used it. In this presentation, Stephen won?t try to > convince you to use it more often. Instead, he?ll present a different > perspective on what this data structure is, and how it differs from a > list. The presentation will compare deques and lists in a visual manner, > to help us understand why we may need a deque in certain situations. > We?ll also explore some demonstration examples to highlight the > differences in performance between the two data structures in different > scenarios. > *pronounced like ?deck" New Zealand-style pronounciation? From PythonList at DancesWithMice.info Wed Nov 8 15:27:42 2023 From: PythonList at DancesWithMice.info (dn) Date: Thu, 9 Nov 2023 09:27:42 +1300 Subject: [Tutor] =?utf-8?q?Clearing_the_Deque_=E2=80=A2_Picturing_Python?= =?utf-8?b?4oCZcyBgZGVxdWVgIGRhdGEgc3RydWN0dXJl?= In-Reply-To: <2d1a00f6-f71a-4c57-8ab0-ccccb58da6c8@wichmann.us> References: <5d0fd65d-d1ab-412c-bf69-2c9d13cef879@DancesWithMice.info> <2d1a00f6-f71a-4c57-8ab0-ccccb58da6c8@wichmann.us> Message-ID: On 09/11/2023 06.08, Mats Wichmann wrote: > On 11/7/23 12:57, dn via Tutor wrote: >> You will be welcome to join us at our next (hybrid) meeting: >> Wednesday, 15 November 2023, 1815~2030 NZDT (0515~0730 UTC). >> >> >> How often do you use a deque*? ?Not very? is a common answer. Perhaps >> you?ve never used it. In this presentation, Stephen won?t try to >> convince you to use it more often. Instead, he?ll present a different >> perspective on what this data structure is, and how it differs from a >> list. The presentation will compare deques and lists in a visual >> manner, to help us understand why we may need a deque in certain >> situations. We?ll also explore some demonstration examples to >> highlight the differences in performance between the two data >> structures in different scenarios. > > >> *pronounced like ?deck" > New Zealand-style pronounciation? Hah! Actually (a very English exclamation), Stephen is based in London! How would you like it pronounced? Yes, 'deequeue' did strike me as appropriate, given the word's meaning; but there are the terms "enqueue" and its converse "de-queue".* * and should a deque/deck therefore have two enqueue terms: pre-queue and post-queue; plus two for de-queuing: un-queue and um-queue? Word of warning: never try to emulate the Kiwi-accent. Actors on TV and in movies NEVER manage it. It's even worse than trying to make-out that New Zealand is part of Australia! (even if it is called "the Auckland Harbour Bridge" on one side, and "the Sydney Harbor Bridge" on the other!) -- Regards, =dn From alan.gauld at yahoo.co.uk Wed Nov 8 18:36:59 2023 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Wed, 8 Nov 2023 23:36:59 +0000 Subject: [Tutor] =?utf-8?q?Clearing_the_Deque_=E2=80=A2_Picturing_Python?= =?utf-8?b?4oCZcyBgZGVxdWVgIGRhdGEgc3RydWN0dXJl?= In-Reply-To: References: <5d0fd65d-d1ab-412c-bf69-2c9d13cef879@DancesWithMice.info> <2d1a00f6-f71a-4c57-8ab0-ccccb58da6c8@wichmann.us> Message-ID: On 08/11/2023 20:27, dn via Tutor wrote: >>> *pronounced like ?deck" >> New Zealand-style pronounciation? > Actually (a very English exclamation), Stephen is based in London! > > How would you like it pronounced? I've only ever heard it pronounced as Dee-Queue. Differentiated from deque in that it is a noun and not a verb. So context is sufficient. I've certainly never heard it called a deck! -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos From mats at wichmann.us Wed Nov 8 18:58:42 2023 From: mats at wichmann.us (Mats Wichmann) Date: Wed, 8 Nov 2023 16:58:42 -0700 Subject: [Tutor] =?utf-8?q?Clearing_the_Deque_=E2=80=A2_Picturing_Python?= =?utf-8?b?4oCZcyBgZGVxdWVgIGRhdGEgc3RydWN0dXJl?= In-Reply-To: References: <5d0fd65d-d1ab-412c-bf69-2c9d13cef879@DancesWithMice.info> <2d1a00f6-f71a-4c57-8ab0-ccccb58da6c8@wichmann.us> Message-ID: <7c49bdf2-e733-4a5e-a5f8-e8837c3145df@wichmann.us> On 11/8/23 16:36, Alan Gauld via Tutor wrote: > On 08/11/2023 20:27, dn via Tutor wrote: > >>>> *pronounced like ?deck" >>> New Zealand-style pronounciation? > >> Actually (a very English exclamation), Stephen is based in London! >> >> How would you like it pronounced? > > I've only ever heard it pronounced as Dee-Queue. > > Differentiated from deque in that it is a noun and not a verb. > So context is sufficient. I've certainly never heard it called > a deck! It has a long history (for me) of being "deck", as that's what Knuth proclaimed, and he was The God Of Computer Science when I was learning, even if he was associated with a bitter-rival university (I studied at UC Berkeley, and of course Knuth was Stanford). I did some hunting and of course the excerpt is on the web - my books are in a box somewhere, not seen for decades: === A deque ("double-ended queue") is a linear list for which all insertions and deletions (and usually all accesses) are made at the ends of the list. A deque is therefore more general than a stack or a queue; it has some properties in common with a deck of cards, and it is pronounced the same way. === And my joke question had to do with somewhat notorious way "deck" comes out (to non-New Zealand / Aussie ears), parodied in a series of phony ads as can be seen here: https://www.youtube.com/watch?v=tm5Hne97BA4 From threesomequarks at proton.me Wed Nov 8 19:43:16 2023 From: threesomequarks at proton.me (ThreeBlindQuarks) Date: Thu, 09 Nov 2023 00:43:16 +0000 Subject: [Tutor] =?utf-8?q?Clearing_the_Deque_=E2=80=A2_Picturing_Python?= =?utf-8?b?4oCZcyBgZGVxdWVgIGRhdGEgc3RydWN0dXJl?= In-Reply-To: References: <5d0fd65d-d1ab-412c-bf69-2c9d13cef879@DancesWithMice.info> <2d1a00f6-f71a-4c57-8ab0-ccccb58da6c8@wichmann.us> Message-ID: <_TyGfYIyHDOkd1SOEKQyQYOezTR-YZW6l3RBBqyCrF-YVKEJFNxNBRZeA2f1EkbmZrlosd0sVjaLEqfZdZD5FQVgQq2BJJYRc2x9kbuKcUg=@proton.me> Alan, I have always heard the word as "Deck" while also have a word from removing something from a Queue (pronounced something like the Japanese ? pronounced kyu or the way some alphabets say the letter Q as de-queue or like DQ or dee-kyu. The opposite is a bit like NQ. As you note, the problem in English is that many verbs become nouns and vice versa and can often become adjectives and adverbs and more. You can queue things in a queue and you can stack things in a stacked stack and of course you can put a deck of cards in a deque. This reminds me a bit of the string theory debate about various version of open versus closed strings that turn out all to be different ways of looking at a higher theory and are all in some sense equally valid. In python, all kinds of data structures and implementation can be used to create a list-like or vector-like data structure with methods that allow any combination of adding or removing or replacing one or more items in front, in back, or in middle, or concatenating multiple such structures or creating other effects like a union or intersection. These "objects" vary in many ways in internal details and ideas about efficiency and underneath it some may be implemented using simple lists, or dictionaries or vectors that can grow and shrink as needed. They can be composite objects, such as for example a set accompanied by a sort of index. Many such designs should be considered horrible. I am reminded at my reaction to an implementation in JavaScript of an Array. A main data structure was re-used in that a dictionary of sorts would be examined and only keys like "53" that looked like a number would be considered and put into numeric order and be viewed as an Array. Elements were allowed to be missing and so on. Implementation could not have been very efficient but it meant you did not need yet another data structure at that time. So back to Deque, it may be that it is what a LIST could have been had they wanted a nice implementation with lots of features. Maybe they could have named it something like schlange or even ouroboros. Sent with Proton Mail secure email. On Wednesday, November 8th, 2023 at 6:36 PM, Alan Gauld via Tutor wrote: > On 08/11/2023 20:27, dn via Tutor wrote: > > > > > *pronounced like ?deck" > > > > New Zealand-style pronounciation? > > > Actually (a very English exclamation), Stephen is based in London! > > > > How would you like it pronounced? > > > I've only ever heard it pronounced as Dee-Queue. > > Differentiated from deque in that it is a noun and not a verb. > So context is sufficient. I've certainly never heard it called > a deck! > > -- > Alan G > Author of the Learn to Program web site > http://www.alan-g.me.uk/ > http://www.amazon.com/author/alan_gauld > Follow my photo-blog on Flickr at: > http://www.flickr.com/photos/alangauldphotos > > > > _______________________________________________ > Tutor maillist - Tutor at python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor From PythonList at DancesWithMice.info Wed Nov 8 20:12:58 2023 From: PythonList at DancesWithMice.info (dn) Date: Thu, 9 Nov 2023 14:12:58 +1300 Subject: [Tutor] =?utf-8?q?Clearing_the_Deque_=E2=80=A2_Picturing_Python?= =?utf-8?b?4oCZcyBgZGVxdWVgIGRhdGEgc3RydWN0dXJl?= In-Reply-To: <7c49bdf2-e733-4a5e-a5f8-e8837c3145df@wichmann.us> References: <5d0fd65d-d1ab-412c-bf69-2c9d13cef879@DancesWithMice.info> <2d1a00f6-f71a-4c57-8ab0-ccccb58da6c8@wichmann.us> <7c49bdf2-e733-4a5e-a5f8-e8837c3145df@wichmann.us> Message-ID: On 09/11/2023 12.58, Mats Wichmann wrote: > On 11/8/23 16:36, Alan Gauld via Tutor wrote: >> On 08/11/2023 20:27, dn via Tutor wrote: >> >>>>> *pronounced like ?deck" >>>> New Zealand-style pronounciation? >> >>> Actually (a very English exclamation), Stephen is based in London! >>> >>> How would you like it pronounced? >> >> I've only ever heard it pronounced as Dee-Queue. >> >> Differentiated from deque in that it is a noun and not a verb. >> So context is sufficient. I've certainly never heard it called >> a deck! That was my introduction to the data-construct too. Which meant I puzzled over the matter (overly philosophically) and concluded it was another trans-Atlantic difference, ie it depended upon which school/skool scheduled/skeduled your learning. The speaker pronounces the term "deck" and it's his talk. So, I'm not about to change his words. Whilst I will happily coach others who are speaking for the first time, or perhaps speaking for the first time, Stephen has considerable experience. We are more interested in talking about 'approach' and methodology to better 'connect' with each attendee. Speaking personally: as the single-ended construct is called a "queue", it seems more logical to retain that pronunciation in the double-ended version. How does "deck" relate to [single-ended] "queue"? There's not even a hint that they are related! I guess we don't face such issues anywhere else. The European assumption that "tuple" starts with a sound like "too", as distinct from others preferring an "up"-like pronunciation is but a figment of our imaginations. Perhaps we should ignore data-structures (and thus classes*) completely, and just jump straight into writing the code... * with this, on top of the sarcasm, @Alan knows I'm baiting him... > It has a long history (for me) of being "deck", as that's what Knuth > proclaimed, and he was The God Of Computer Science when I was learning, > even if he was associated with a bitter-rival university (I studied at > UC Berkeley, and of course Knuth was Stanford). > > I did some hunting and of course the excerpt is on the web - my books > are in a box somewhere, not seen for decades: > > === > A deque ("double-ended queue") is a linear list for which all insertions > and deletions (and usually all accesses) are made at the ends of the > list. A deque is therefore more general than a stack or a queue; it has > some properties in common with a deck of cards, and it is pronounced the > same way. > === The speed and efficiency of decks/deques, compared with standard lists and much-favored stacks, is exactly the point that our speaker will be making! Everyone is welcome to come along to the (hybrid) meeting: Wednesday, 15 November 2023, 1815~2030 NZDT (0515~0730 UTC). RSVP at https://www.meetup.com/nzpug-auckland/events/295433874/ (speaking of language, I noticed a tendency to say "Please RSVP" or "Reply by RSVP-ing", which duplicates the meaning of the (originally French) term RSVP - just as many folk talk of "PIN-numbers") > And my joke question had to do with somewhat notorious way "deck" comes > out (to non-New Zealand / Aussie ears), parodied in a series of phony > ads as can be seen here: > https://www.youtube.com/watch?v=tm5Hne97BA4 To confirm your opinion that I have no sense of humor (hah!), please would you confirm reading my warning about people attempting to imitate the New Zealand accent. The video-guy didn't! He sounds Dutch South African (per that "ew" of tuple!) and when he came out with "pro-duck-t", sealed his own can, um, fate! Australians (and others) like to have a go at the Kiwi pronunciation of "fish and chips" (BTW largely unknown in the US) as "fush and cheeps". I have heard something of the first - yet it was from Kiwis who had spend some time in Australia. I've lent my phonetic-ear to this claim, over the years, and have never really heard it. Of course, like other countries, there are regional variations in accent. The "cheeps" for "chips" does give rise to the phrase "cheap as chips". Kiwi-English is much more like English-English. Aussie-English is much more American. Let me know when you're coming-over. We'll say "gidday" (and not the different, Australian, version) and see (and hear) the real deal! I'll happily introduce you to words like "paua", and if you can pronounce it, show you around "Wakarewarewa". How about "Waikaremoana" (or should we let her walk?). Speaking of (silly) walks, must get back to (pronouncing it) Python and a PUG meeting in the States (where during the set-up, the MC had the politesse to check pronunciation of the speaker's Polish name - he needed several tries to get it reasonably-correct. These things are so much easier for those of us who are multi-lingual)! -- Regards, =dn From roel at roelschroeven.net Wed Nov 8 18:53:38 2023 From: roel at roelschroeven.net (Roel Schroeven) Date: Thu, 9 Nov 2023 00:53:38 +0100 Subject: [Tutor] =?utf-8?q?Clearing_the_Deque_=E2=80=A2_Picturing_Python?= =?utf-8?b?4oCZcyBgZGVxdWVgIGRhdGEgc3RydWN0dXJl?= In-Reply-To: References: <5d0fd65d-d1ab-412c-bf69-2c9d13cef879@DancesWithMice.info> <2d1a00f6-f71a-4c57-8ab0-ccccb58da6c8@wichmann.us> Message-ID: <317e23dd-10e2-478d-968a-b7faf1db9ea9@roelschroeven.net> Alan Gauld via Tutor schreef op 9/11/2023 om 0:36: > On 08/11/2023 20:27, dn via Tutor wrote: > > >>> *pronounced like ?deck" > >> New Zealand-style pronounciation? > > > Actually (a very English exclamation), Stephen is based in London! > > > > How would you like it pronounced? > > I've only ever heard it pronounced as Dee-Queue. > > Differentiated from deque in that it is a noun and not a verb. > So context is sufficient. I've certainly never heard it called > a deck! When used as the name for the data structure, both pronunciations are used apparently, but _deck_ seems to be more common on Youtube: https://youglish.com/pronounce/deque/english? _Deck_ is what I've always used in any case, though that probably doesn't say much since I'm not a native English speaker. -- "Experience is that marvelous thing that enables you to recognize a mistake when you make it again." -- Franklin P. Jones From phillor9 at gmail.com Fri Nov 10 00:05:30 2023 From: phillor9 at gmail.com (Phil) Date: Fri, 10 Nov 2023 15:05:30 +1000 Subject: [Tutor] Custom Tkinter widgets part 2 Message-ID: David answered my first custom widgets question in February this year and I have created several widgets since then based on his answer.? I discovered an alternative method a few months ago and it also works well until I decided to add a label. I have created a dial widget (and multiple dial widgets of varying sizes) which displays correctly now I want to add a label below the dial to display the dial's value. So far I'm only able to display the dial or the label but not both at the same time. I hope these code snippets will be enough show how I'm attempting to display both widgets. First the DIAL class: import tkinter as tk import math class DIAL(tk.Canvas): ??? def __init__(self, master, dial_type="semi", bg="white", *args, **kwargs): ??????? super().__init__(master, *args, **kwargs) ??????? self.configure(width=100, height=100, bd=0, highlightthickness=0) ??????? self.min_value = 0 ??????? self.max_value = 100 ??????? self.value = 50 ??????? self.dial_type = dial_type ??????? self.bg = bg ??????? self.draw_dial() ??????? # Create a label to display the dial value ??????? self.label = tk.Label(self, text=f"{self.value}") ??????? #self.label.pack(side="bottom") # I think I can see why this won't display the label on the canvas ??? def draw_dial(self): And here's part of a dial demo: ??? root = tk.Tk() ??? root.title("Dial Widget Example") ??? full_dial = DIAL(root, width=150, height=150, dial_type="full", bg="red") ??? full_dial.pack(padx=20, pady=20) # dial or dials all display correctly ??? full_dial.label.pack(side="bottom") # the label needs to be displayed on the canvas but this method is wrong. This is one of several attempts that I've tried. As it stands the label is displayed where the dial would have been if I'd left out the line "full_dial.label.pack(side="bottom")". Hopefully, the correction is a simple syntax error rather the a design flaw. ?-- Regards, Phil From alan.gauld at yahoo.co.uk Fri Nov 10 04:40:12 2023 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Fri, 10 Nov 2023 09:40:12 +0000 Subject: [Tutor] Custom Tkinter widgets part 2 In-Reply-To: References: Message-ID: On 10/11/2023 05:05, Phil wrote: > First the DIAL class: > class DIAL(tk.Canvas): My first thought is that when creating any kind of custom widget I start by inheriting from Frame. Frames can contain anything and are self contained in terms of geometry management. Canvases can contain most things so it should work but just a thought. > ??? def __init__(self, master, dial_type="semi", bg="white", *args, > **kwargs): > ??????? super().__init__(master, *args, **kwargs) > ??????? self.configure(width=100, height=100, bd=0, highlightthickness=0) > > ??????? self.min_value = 0 > ??????? self.max_value = 100 > ??????? self.value = 50 > ??????? self.dial_type = dial_type > ??????? self.bg = bg > > ??????? self.draw_dial() > > ??????? # Create a label to display the dial value > > ??????? self.label = tk.Label(self, text=f"{self.value}") > ??????? #self.label.pack(side="bottom") # I think I can see why this > won't display the label on the canvas > > ??? def draw_dial(self): > > And here's part of a dial demo: > > ??? root = tk.Tk() > ??? root.title("Dial Widget Example") > > ??? full_dial = DIAL(root, width=150, height=150, dial_type="full", > bg="red") > ??? full_dial.pack(padx=20, pady=20) # dial or dials all display correctly > ??? full_dial.label.pack(side="bottom") # the label needs to be > displayed on the canvas but this method is wrong. You shouldn't have to pack the label twice. I don't know what draw_dial does, but the fact you pack the label into the Canvas means you should only need to pack the Canvas in the client code. > This is one of several attempts that I've tried. As it stands the label > is displayed where the dial would have been if I'd left out the line > "full_dial.label.pack(side="bottom")". I'm not sure what that means. Can you post the entire DIAL code? Hopefully it's not dependant on anything else? That way we can run it rather than guess what is happening. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos From phillor9 at gmail.com Fri Nov 10 23:05:22 2023 From: phillor9 at gmail.com (Phil) Date: Sat, 11 Nov 2023 14:05:22 +1000 Subject: [Tutor] Custom Tkinter widgets part 2 In-Reply-To: <21bf1188-7123-c010-d1b6-21837b77fb3d@yahoo.co.uk> References: <21bf1188-7123-c010-d1b6-21837b77fb3d@yahoo.co.uk> Message-ID: On 11/11/23 09:50, Alan Gauld wrote: >> I can, but the example code amounts to around 130 lines. > Thats about the limit but still just about OK. After a little tweaking, Alan, the dial is working as I had expected. Even so, there may be other tweaks or design improvements that could be added. I'm happy with the class the way it is and will probably now move onto something else. However, I'm also happy to post the code either to the list or to you privately (since you replied to me privately and to the list) to review. -- Regards, Phil From alan.gauld at yahoo.co.uk Sat Nov 11 19:31:02 2023 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Sun, 12 Nov 2023 00:31:02 +0000 Subject: [Tutor] Custom Tkinter widgets part 2 In-Reply-To: References: <21bf1188-7123-c010-d1b6-21837b77fb3d@yahoo.co.uk> Message-ID: On 11/11/2023 04:05, Phil wrote: > the dial is working If you are happy that's fine. Normally I'd say post it out of curiosity but I'm kind of busy with other stuff just now! :-) -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos From tannu.dekeza at gmail.com Sun Nov 12 04:45:43 2023 From: tannu.dekeza at gmail.com (Tannu Dekeza) Date: Sun, 12 Nov 2023 11:45:43 +0200 Subject: [Tutor] ImportError Message-ID: Hi *I'm a beginner at python programming. I have been trying to execute the below code and have been getting an import error for numpy. i am using jupyter notebook. i have reinstalled both python and jupyter notebook but the error always occurs when i restart a kernel. how can i solve this permanently * import numpy as np import pandas as pd import math import xlsxwriter import requests ImportError Traceback (most recent call last) Cell In[1], line 1----> 1 import numpy as np 2 import pandas as pd 3 import math File ~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\numpy\__init__.py:171 169 from . import fft 170 from . import polynomial--> 171 from . import random 172 from . import ctypeslib 173 from . import ma File ~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\numpy\random\__init__.py:180 126 __all__ = [ 127 'beta', 128 'binomial', (...) 176 'zipf', 177 ] 179 # add these for module-freeze analysis (like PyInstaller)--> 180 from . import _pickle 181 from . import _common 182 from . import _bounded_integers File ~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\numpy\random\_pickle.py:1----> 1 from .mtrand import RandomState 2 from ._philox import Philox 3 from ._pcg64 import PCG64, PCG64DXSM File numpy\\random\\mtrand.pyx:1, in init numpy.random.mtrand() File bit_generator.pyx:40, in init numpy.random.bit_generator() ImportError: cannot import name randbits From mats at wichmann.us Sun Nov 12 17:09:04 2023 From: mats at wichmann.us (Mats Wichmann) Date: Sun, 12 Nov 2023 15:09:04 -0700 Subject: [Tutor] ImportError In-Reply-To: References: Message-ID: <515bf911-320f-41af-b1b9-3e3fcb8807e4@wichmann.us> On 11/12/23 02:45, Tannu Dekeza wrote: > Hi > > *I'm a beginner at python programming. I have been trying to execute > the below code and have been getting an import error for numpy. i am > using jupyter notebook. i have reinstalled both python and jupyter > notebook but the error always occurs when i restart a kernel. how can > i solve this permanently * > > > > import numpy as np > import pandas as pd > import math > import xlsxwriter > import requests > > > > ImportError Traceback (most recent call last) > Cell In[1], line 1----> 1 import numpy as np 2 import pandas as > pd 3 import math > > File ~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\numpy\__init__.py:171 > 169 from . import fft 170 from . import polynomial--> 171 from . > import random 172 from . import ctypeslib 173 from . import ma > > File ~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\numpy\random\__init__.py:180 > 126 __all__ = [ 127 'beta', 128 'binomial', (...) > 176 'zipf', 177 ] 179 # add these for module-freeze > analysis (like PyInstaller)--> 180 from . import _pickle 181 from . > import _common 182 from . import _bounded_integers > > File ~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\numpy\random\_pickle.py:1----> > 1 from .mtrand import RandomState 2 from ._philox import Philox > 3 from ._pcg64 import PCG64, PCG64DXSM > > File numpy\\random\\mtrand.pyx:1, in init numpy.random.mtrand() > > File bit_generator.pyx:40, in init numpy.random.bit_generator() > ImportError: cannot import name randbits There's a "randbits" in the Python standard library "secrets" module. When you get this sort of error (failing to import a name rather than a module), it usually means you're covering up the module it should have been imported from, although if that's the case I would have expected a slightly more complete error message. Check if by any chance your project has a local secrets.py file or a secrets module. It could be more complicated than this, but this would be the place to start. Try just starting a plain Python interpreter and, at the >>> prompt, doing: from secrets import randbits and seeing if that gives you any weird messages. The numpy and other data science toolkits have their own groups, you may be better placed asking there - it may be that they recognize this problem from something (like incorrect setting of search paths), in case they have local copies of some kind of secrets module that needs to be kept clear of the Python one - I, at least, don't know anything about this world, *possibly* someone else here knowns. From phillor9 at gmail.com Thu Nov 16 03:38:32 2023 From: phillor9 at gmail.com (Phil) Date: Thu, 16 Nov 2023 18:38:32 +1000 Subject: [Tutor] how can a value be retrieved from an event loop? Message-ID: Thank for reading this. This knob class does what it's supposed to do but I cannot see how to retrieve the angle or set the angle from an instance of the class. The angle can be retrieved and printed from within the event loop but not outside the loop. I've found a similar class that does return a value to an instance of the class but it's vastly more complicated than what I've presented here and even though it's similar I cannot fathom how it works. Is there a simple fix or is there a major flaw in the design? import tkinter as tk import math class KNOB(tk.Canvas): ??? def __init__( ??????? self, ??????? parent, ??????? size=100 ??? ): ??????? super().__init__(parent, width=size, height=size) ??????? self.size = size ??????? self.color1 = "#007DC8" ??????? self.color2 = "#98D2D2" ??????? self.angle = 0 ??????? self.border = self.create_oval( ??????????? 0.1 * size, ??????????? 0.1 * size, ??????????? 0.9 * size, ??????????? 0.9 * size, ??????????? outline=self.color1, ??????????? width=3, ??????????? fill=self.color2, ??????? ) ??????? self.dot = self.create_oval( ??????????? 0.45 * size, ??????????? 0.20 * size, ??????????? 0.55 * size, ??????????? 0.30 * size, ??????????? outline=self.color1, ??????????? width=3, ??????? ) ??????? self.bind("", self.turn_clockwise) ??????? self.bind("", self.turn_counterwise) ??? def turn_clockwise(self, event): ??????? self.delete(self.dot) ??????? self.angle = self.angle + 0.1 ??????? centerX = 0.5 * self.size + (0.25 * self.size * math.sin(self.angle)) ??????? centerY = 0.5 * self.size - (0.25 * self.size * math.cos(self.angle)) ??????? self.dot = self.create_oval( ??????????? (centerX - 0.05 * self.size), ??????????? (centerY - 0.05 * self.size), ??????????? (centerX + 0.05 * self.size), ??????????? (centerY + 0.05 * self.size), ??????????? outline=self.color1, ??????????? width=3, ??????? ) ??????? #print(self.angle) ??????? #return self.angle ??? def turn_counterwise(self, event): ??????? self.delete(self.dot) ??????? self.angle = self.angle - 0.1 ??????? centerX = 0.5 * self.size + (0.25 * self.size * math.sin(self.angle)) ??????? centerY = 0.5 * self.size - (0.25 * self.size * math.cos(self.angle)) ??????? self.dot = self.create_oval( ??????????? (centerX - 0.05 * self.size), ??????????? (centerY - 0.05 * self.size), ??????????? (centerX + 0.05 * self.size), ??????????? (centerY + 0.05 * self.size), ??????????? outline=self.color1, ??????????? width=3, ??????? ) ??????? #print(self.get_angle()) ??? def get_angle(self): ??????? print("get_angle called") ??????? return self.angle ??? def set_angle(self, angle): ??????? self.angle = angle if __name__ == "__main__": ??? root = tk.Tk() ??? root.title("Knob test") ??? knob = KNOB(root) ??? knob.pack(padx=20, pady=20) ??? print(knob.get_angle()) # this returns 0? once but the angle value is not updated here ??? knob.set_angle(15) # this sets the angle but only once the mouse button is pressed ??? root.mainloop() -- Regards, Phil From alan.gauld at yahoo.co.uk Thu Nov 16 05:02:58 2023 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Thu, 16 Nov 2023 10:02:58 +0000 Subject: [Tutor] how can a value be retrieved from an event loop? In-Reply-To: References: Message-ID: On 16/11/2023 08:38, Phil wrote: > angle can be retrieved and printed from within the event loop but not > outside the loop. That would be how you normally do things. You should be ale to access the values outside the mainloop(as you do in the code below) but changes won't show up on the GUI until the mainloop runs (unless who do a whole lot of extra stiff that the mainloop normally does for you) > class KNOB(tk.Canvas): > ??? def __init__( > ??????? self, > ??????? parent, > ??????? size=100 > ??? ): > ??????? super().__init__(parent, width=size, height=size) > > ??????? self.size = size > ??????? self.color1 = "#007DC8" > ??????? self.color2 = "#98D2D2" > ??????? self.angle = 0 > > ??????? self.border = self.create_oval( > ??????????? 0.1 * size, > ??????????? 0.1 * size, > ??????????? 0.9 * size, > ??????????? 0.9 * size, > ??????????? outline=self.color1, > ??????????? width=3, > ??????????? fill=self.color2, > ??????? ) > > ??????? self.dot = self.create_oval( > ??????????? 0.45 * size, > ??????????? 0.20 * size, > ??????????? 0.55 * size, > ??????????? 0.30 * size, > ??????????? outline=self.color1, > ??????????? width=3, > ??????? ) You could simplify your code by creating a draw_dot() method which you use here and in the two event handlers below. > > ??????? self.bind("", self.turn_clockwise) > ??????? self.bind("", self.turn_counterwise) > > ??? def turn_clockwise(self, event): > ??????? self.delete(self.dot) > ??????? self.angle = self.angle + 0.1 > ??????? centerX = 0.5 * self.size + (0.25 * self.size * > math.sin(self.angle)) > ??????? centerY = 0.5 * self.size - (0.25 * self.size * > math.cos(self.angle)) > ??????? self.dot = self.create_oval( > ??????????? (centerX - 0.05 * self.size), > ??????????? (centerY - 0.05 * self.size), > ??????????? (centerX + 0.05 * self.size), > ??????????? (centerY + 0.05 * self.size), > ??????????? outline=self.color1, > ??????????? width=3, > ??????? ) > ??????? #print(self.angle) > ??????? #return self.angle > > ??? def turn_counterwise(self, event): > ??????? self.delete(self.dot) > ??????? self.angle = self.angle - 0.1 > ??????? centerX = 0.5 * self.size + (0.25 * self.size * > math.sin(self.angle)) > ??????? centerY = 0.5 * self.size - (0.25 * self.size * > math.cos(self.angle)) > ??????? self.dot = self.create_oval( > ??????????? (centerX - 0.05 * self.size), > ??????????? (centerY - 0.05 * self.size), > ??????????? (centerX + 0.05 * self.size), > ??????????? (centerY + 0.05 * self.size), > ??????????? outline=self.color1, > ??????????? width=3, > ??????? ) > ??????? #print(self.get_angle()) > > ??? def get_angle(self): > ??????? print("get_angle called") > ??????? return self.angle > > ??? def set_angle(self, angle): > ??????? self.angle = angle > > if __name__ == "__main__": > ??? root = tk.Tk() > ??? root.title("Knob test") > > ??? knob = KNOB(root) > ??? knob.pack(padx=20, pady=20) > > ??? print(knob.get_angle()) # this returns 0? once but the angle value > is not updated here Which is as expected since you only call this once and the method only prints the value not change it.. > ??? knob.set_angle(15) # this sets the angle but only once the mouse > button is pressed You are changing the value in the object but you are not updating the GUI. Even calling the turnXXX handlers will not do that, you need to get into processing the widgets and painting them on screen. That's the extra sauce that the event loop does for you. > ??? root.mainloop() If you called the turnXXX handlers before mainloop() the changes should become visible once the loop runs. I'm not quite sure what you are trying to achieve by accessing/changing the value before the loop starts, it's not something I've ever needed to do in a GUI program, but it should certainly be possible. And from your description is working as expected. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos From learn2program at gmail.com Thu Nov 16 06:13:00 2023 From: learn2program at gmail.com (Alan Gauld) Date: Thu, 16 Nov 2023 11:13:00 +0000 Subject: [Tutor] how can a value be retrieved from an event loop? In-Reply-To: <325f1f1d-478f-4b8a-b99b-04a1b6b56474@gmail.com> References: <325f1f1d-478f-4b8a-b99b-04a1b6b56474@gmail.com> Message-ID: <9ee04f6f-6bbf-555b-134c-46a8c6ea94a4@yahoo.co.uk> On 16/11/2023 10:31, Phil wrote: > What I have in mind is to have the knob class return values to the > instance app and use it just like a scale widget. > > To set an angle from the instance code this is what I have done: I'm slight confused by your terminology here. A class is a template from which you create instances. Instances present an API to which you can send "messages" (aka call functions) Those functions are implemented in the class definition but each instance offers them independently. So I don't really understand what you mean by the class returns values to the instance app? The class creates an instance. The instances should return values. > knob.set_angle(15) which does set the angle but only once I've clicked > on the knob and started the event loop. > > So, should I call turn_clockwise() before I call knob.set() and what > arguments should I pass to the turn method? If so, that seems a bit > clumsy. I don't have to do anything like that to get values from a scale > widget. Getting values should be straightforward. It's setting them that's hard. At least, making the new value display is hard, just setting the value is easy. I still don't understand what it is that you are trying to do that requires you to set/get values of widgets outside the mainloop? Apart from initialising the widgets (which should be inside the __init__), anything you need to do should be possible inside the loop. It seems like you are fighting the framework for no obvious purpose. The event loop is there to make your life easier, why not use it? -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos From phillor9 at gmail.com Thu Nov 16 06:35:46 2023 From: phillor9 at gmail.com (Phil) Date: Thu, 16 Nov 2023 21:35:46 +1000 Subject: [Tutor] how can a value be retrieved from an event loop? In-Reply-To: <9ee04f6f-6bbf-555b-134c-46a8c6ea94a4@yahoo.co.uk> References: <325f1f1d-478f-4b8a-b99b-04a1b6b56474@gmail.com> <9ee04f6f-6bbf-555b-134c-46a8c6ea94a4@yahoo.co.uk> Message-ID: On 16/11/23 21:13, Alan Gauld wrote:de this is what I have done: > I'm slight confused by your terminology here. > A class is a template from which you create instances. > Instances present an API to which you can send "messages" > (aka call functions) Those functions are implemented > in the class definition but each instance offers them > independently. > > So I don't really understand what you mean by the class > returns values to the instance app? The class creates > an instance. The instances should return values. It's getting late and time for bed. Forget what I said about the class returning anything. What I'm trying to do is create a knob that works in the same fashion as the scale widget. I think I'm correct in saying that the scale is a class, or part of a widget class, and to use it I import scale (tk.Tk) into an app class. The scale's value is then available to be feed into a label, for instance. It seemed simple enough to create a knob class but I'm missing something. I just want to replace the scale with a knob. -- Regards, Phil From alan.gauld at yahoo.co.uk Thu Nov 16 08:45:57 2023 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Thu, 16 Nov 2023 13:45:57 +0000 Subject: [Tutor] how can a value be retrieved from an event loop? In-Reply-To: References: <325f1f1d-478f-4b8a-b99b-04a1b6b56474@gmail.com> <9ee04f6f-6bbf-555b-134c-46a8c6ea94a4@yahoo.co.uk> Message-ID: On 16/11/2023 11:35, Phil wrote: > What I'm trying to do is create a knob that works in the same fashion as > the scale widget. OK, I took your code and tweaked it to do what I think you want. Note that you now set the initial angle by passing it to the constructor call. Also note that the angle is in radians so if you want to use degrees you will need to do a bit of math inside the code. ============= import tkinter as tk import math class KNOB(tk.Canvas): def __init__( self, parent, size=100, angle=0 ): super().__init__(parent, width=size, height=size) self.size = size self.color1 = "#007DC8" self.color2 = "#98D2D2" self.angle = angle self.border = self.create_oval( 0.1 * size, 0.1 * size, 0.9 * size, 0.9 * size, outline=self.color1, width=3, fill=self.color2, ) self.dot = None # make a "dot" for first draw_dot to remove! self.draw_dot() self.bind("", self.turn_clockwise) self.bind("", self.turn_counterwise) def draw_dot(self): self.delete(self.dot) centerX = 0.5 * self.size + (0.25 * self.size * math.sin(self.angle)) centerY = 0.5 * self.size - (0.25 * self.size * math.cos(self.angle)) self.dot = self.create_oval( (centerX - 0.05 * self.size), (centerY - 0.05 * self.size), (centerX + 0.05 * self.size), (centerY + 0.05 * self.size), outline=self.color1, width=3, ) def turn_clockwise(self, event): self.angle = self.angle + 0.1 self.draw_dot() self.get_angle() def turn_counterwise(self, event): self.angle = self.angle - 0.1 self.draw_dot() self.get_angle() def get_angle(self): print(self.angle) return self.angle def set_angle(self, angle): self.angle = angle self.get_angle() if __name__ == "__main__": root = tk.Tk() root.title("Knob test") knob = KNOB(root, angle=15) knob.pack(padx=20, pady=20) root.mainloop() -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos From alan.gauld at yahoo.co.uk Thu Nov 16 10:12:59 2023 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Thu, 16 Nov 2023 15:12:59 +0000 Subject: [Tutor] how can a value be retrieved from an event loop? In-Reply-To: References: <325f1f1d-478f-4b8a-b99b-04a1b6b56474@gmail.com> <9ee04f6f-6bbf-555b-134c-46a8c6ea94a4@yahoo.co.uk> Message-ID: On 16/11/2023 13:45, Alan Gauld via Tutor wrote: > OK, I took your code and tweaked it to do what I think you want. > Note that you now set the initial angle by passing it to the > constructor call. I was sufficiently intrigued by this that I took another pass and added a label to demonstrate how it could be used and did the display conversion to degrees too. I hope that it's helpful. I also tidied up the code some more. import tkinter as tk import math class KNOB(tk.Canvas): def __init__( self, parent, size=100, angle=0, string_var = None ): super().__init__(parent, width=size, height=size) self.size = size self.color1 = "#007DC8" self.color2 = "#98D2D2" self.angle = angle % (2 * math.pi) # keep within 0-2pi self.str_var = string_var self.border = self.create_oval( 0.1 * size, 0.1 * size, 0.9 * size, 0.9 * size, outline=self.color1, width=3, fill=self.color2, ) self.dot = None # make a "dot" for first draw_dot to remove! self.draw_dot() self.bind("", self.turn_clockwise) self.bind("", self.turn_counterwise) def draw_dot(self): self.delete(self.dot) centerX = 0.5 * self.size + (0.25 * self.size * math.sin(self.angle)) centerY = 0.5 * self.size - (0.25 * self.size * math.cos(self.angle)) self.dot = self.create_oval( (centerX - 0.05 * self.size), (centerY - 0.05 * self.size), (centerX + 0.05 * self.size), (centerY + 0.05 * self.size), outline=self.color1, width=3, ) if self.str_var: self.str_var.set("%5.2f deg." % math.degrees(self.angle)) def turn_clockwise(self, event): self.set_angle(self.angle + 0.1) self.draw_dot() def turn_counterwise(self, event): self.set_angle(self.angle - 0.1) self.draw_dot() def set_angle(self,angle): self.angle = angle % (2*math.pi) # keep within 0-2pi range if __name__ == "__main__": root = tk.Tk() root.title("Knob test") knob_angle = tk.StringVar() knob_angle.set("0") knob = KNOB(root, angle=15, string_var = knob_angle) knob.pack(padx=20, pady=20) lbl = tk.Label(root, textvariable=knob_angle) lbl.pack() root.mainloop() -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos From phillor9 at gmail.com Thu Nov 16 18:20:38 2023 From: phillor9 at gmail.com (Phil) Date: Fri, 17 Nov 2023 09:20:38 +1000 Subject: [Tutor] how can a value be retrieved from an event loop? In-Reply-To: References: <325f1f1d-478f-4b8a-b99b-04a1b6b56474@gmail.com> <9ee04f6f-6bbf-555b-134c-46a8c6ea94a4@yahoo.co.uk> Message-ID: <61a6ea15-5dcc-43be-bca4-034efa70285e@gmail.com> On 17/11/23 01:12, Alan Gauld via Tutor wrote: > I was sufficiently intrigued by this that I took another pass > and added a label to demonstrate how it could be used and > did the display conversion to degrees too. I hope that it's > helpful. I also tidied up the code some more. Thank you Alan, I never thought of using string_var. I was concentrating on using "command=on_change" but couldn't get it to work. I'll do a bit more research on that later. I have a medical appointment in a couple of hours so I don't have time to study your code at the moment. Thank you again Alan, your time is very much appreciated. -- Regards, Phil From alan.gauld at yahoo.co.uk Fri Nov 17 05:02:28 2023 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Fri, 17 Nov 2023 10:02:28 +0000 Subject: [Tutor] how can a value be retrieved from an event loop? In-Reply-To: <61a6ea15-5dcc-43be-bca4-034efa70285e@gmail.com> References: <325f1f1d-478f-4b8a-b99b-04a1b6b56474@gmail.com> <9ee04f6f-6bbf-555b-134c-46a8c6ea94a4@yahoo.co.uk> <61a6ea15-5dcc-43be-bca4-034efa70285e@gmail.com> Message-ID: On 16/11/2023 23:20, Phil wrote: > On 17/11/23 01:12, Alan Gauld via Tutor wrote: >> I was sufficiently intrigued by this that I took another pass >> and added a label to demonstrate how it could be used and > Thank you Alan, I never thought of using string_var. You could use an IntVar just as easily (and avoid the string conversion) but I used StringVar because a string is more easily formatted. The key thing is that the Tkinter Var objects allow communication between two widgets automatically without you having to do anything other than assign the same Var to each widget. It was your comment that you wanted something like Scale that triggered the idea - that's how Scale works too. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos From phillor9 at gmail.com Fri Nov 17 17:15:03 2023 From: phillor9 at gmail.com (Phil) Date: Sat, 18 Nov 2023 08:15:03 +1000 Subject: [Tutor] how can a value be retrieved from an event loop? In-Reply-To: References: <325f1f1d-478f-4b8a-b99b-04a1b6b56474@gmail.com> <9ee04f6f-6bbf-555b-134c-46a8c6ea94a4@yahoo.co.uk> <61a6ea15-5dcc-43be-bca4-034efa70285e@gmail.com> Message-ID: <7ad6bb04-e4c3-45e5-8b5b-069f78350abf@gmail.com> On 17/11/23 20:02, Alan Gauld via Tutor wrote: > It was your comment that you wanted something like Scale > that triggered the idea - that's how Scale works too. Thank you again Alan, I had? look through my past projects and I see that I've used scale with "command=on_change" quite often but I've "variable=" in conjunction with?? IntVar and DoublrVar. I've? also discovered that I've used "command=" in my Led class to detect when the status of a led has changed, so I could probably have used that idea the get a value from the knob class as well. I used to be able to read a text book from cover to cover and then do well in an exam, now I cannot even remember reading the book. A failing memory is just yet another frustration of ageing. -- Regards, Phil From PythonList at danceswithmice.info Fri Nov 17 18:51:19 2023 From: PythonList at danceswithmice.info (DL Neil) Date: Sat, 18 Nov 2023 12:51:19 +1300 Subject: [Tutor] how can a value be retrieved from an event loop? In-Reply-To: <7ad6bb04-e4c3-45e5-8b5b-069f78350abf@gmail.com> References: <325f1f1d-478f-4b8a-b99b-04a1b6b56474@gmail.com> <9ee04f6f-6bbf-555b-134c-46a8c6ea94a4@yahoo.co.uk> <61a6ea15-5dcc-43be-bca4-034efa70285e@gmail.com> <7ad6bb04-e4c3-45e5-8b5b-069f78350abf@gmail.com> Message-ID: <8b5a6f59-476f-d120-9989-6aebda9708a9@DancesWithMice.info> On 11/18/23 11:15, Phil wrote: > I used to be able to read a text book from cover to cover and then do > well in an exam, now I cannot even remember reading the book. A > failing memory is just yet another frustration of ageing. We were taught to make notes as we read - something that has passed out-of-favor. Nevertheless, psychology tells us that if we write notes we are more likely to remember* (so, why write the notes then?), and if we re-read those notes at the end of the day (for example), and then againt at the end of the week; the "spaced repetition" assists transfer from short-term, to long-term memory! Even our digirati grand-children suddenly discover (a) the value of taking notes, and (b) the pyschology of writing with a pen cf typing - which may be even more of a surprise! * more likely than if we didn't take notes -- Regards =dn Research topic: Cognitive Psychology From phillor9 at gmail.com Fri Nov 17 19:50:35 2023 From: phillor9 at gmail.com (Phil) Date: Sat, 18 Nov 2023 10:50:35 +1000 Subject: [Tutor] how can a value be retrieved from an event loop? In-Reply-To: <8b5a6f59-476f-d120-9989-6aebda9708a9@DancesWithMice.info> References: <325f1f1d-478f-4b8a-b99b-04a1b6b56474@gmail.com> <9ee04f6f-6bbf-555b-134c-46a8c6ea94a4@yahoo.co.uk> <61a6ea15-5dcc-43be-bca4-034efa70285e@gmail.com> <7ad6bb04-e4c3-45e5-8b5b-069f78350abf@gmail.com> <8b5a6f59-476f-d120-9989-6aebda9708a9@DancesWithMice.info> Message-ID: On 18/11/23 09:51, DL Neil via Tutor wrote: > Even our digirati grand-children suddenly discover (a) the value of > taking notes, and (b) the pyschology of writing with a pen cf typing - > which may be even more of a surprise! I have many files, named by subject, which I interrogate whenever I cannot remember the syntax of a command or how to solve a particular programming problem. One complication is that these files have become quite large and often a note cannot be specially categorised is slot into one file. I also use duckduckgo a lot but I don't always have access to the Internet. Anyway, I just have to make the best of the situation that I've fallen into. -- Regards, Phil From PythonList at danceswithmice.info Fri Nov 17 20:02:41 2023 From: PythonList at danceswithmice.info (DL Neil) Date: Sat, 18 Nov 2023 14:02:41 +1300 Subject: [Tutor] how can a value be retrieved from an event loop? In-Reply-To: References: <325f1f1d-478f-4b8a-b99b-04a1b6b56474@gmail.com> <9ee04f6f-6bbf-555b-134c-46a8c6ea94a4@yahoo.co.uk> <61a6ea15-5dcc-43be-bca4-034efa70285e@gmail.com> <7ad6bb04-e4c3-45e5-8b5b-069f78350abf@gmail.com> <8b5a6f59-476f-d120-9989-6aebda9708a9@DancesWithMice.info> Message-ID: <0804d99b-0438-0dac-21ea-b9666382889e@DancesWithMice.info> On 11/18/23 13:50, Phil wrote: > > On 18/11/23 09:51, DL Neil via Tutor wrote: > >> Even our digirati grand-children suddenly discover (a) the value of >> taking notes, and (b) the pyschology of writing with a pen cf typing >> - which may be even more of a surprise! > > I have many files, named by subject, which I interrogate whenever I > cannot remember the syntax of a command or how to solve a particular > programming problem. One complication is that these files have become > quite large and often a note cannot be specially categorised is slot > into one file. > > I also use duckduckgo a lot but I don't always have access to the > Internet. Anyway, I just have to make the best of the situation that > I've fallen into. > For many years I've been running WordPress locally. The search-engine yields relevant notes, even if it/they have not been filed under that heading (or 'tagged'). More recently I came across the Zettelkasten Method which, as its name implies, has a more teutonic approach to 'being organised'. Of course, these things are best approached with a flexible attitude, working-out what works for oneself and discarding the rest (without guilt). Using their software and Markdown documents is a significantly 'lighter' approach to mine! Plus should give that multi-dimensional retrieval capability we both seek... -- Regards =dn From phillor9 at gmail.com Fri Nov 17 23:17:04 2023 From: phillor9 at gmail.com (Phil) Date: Sat, 18 Nov 2023 14:17:04 +1000 Subject: [Tutor] how can a value be retrieved from an event loop? In-Reply-To: <0804d99b-0438-0dac-21ea-b9666382889e@DancesWithMice.info> References: <325f1f1d-478f-4b8a-b99b-04a1b6b56474@gmail.com> <9ee04f6f-6bbf-555b-134c-46a8c6ea94a4@yahoo.co.uk> <61a6ea15-5dcc-43be-bca4-034efa70285e@gmail.com> <7ad6bb04-e4c3-45e5-8b5b-069f78350abf@gmail.com> <8b5a6f59-476f-d120-9989-6aebda9708a9@DancesWithMice.info> <0804d99b-0438-0dac-21ea-b9666382889e@DancesWithMice.info> Message-ID: <6349889d-fb75-4f01-a509-abd475a8a0c3@gmail.com> On 18/11/23 11:02, DL Neil via Tutor wrote: > Using their software and Markdown documents is a significantly > 'lighter' approach to mine! Plus should give that multi-dimensional > retrieval capability we both seek... Thank you Denis for your suggestions. I can see that I need to be better organised and with perhaps a better search method. I'll give this some more thought. -- Regards, Phil From boguslaw.gorski at itm.turek.pl Tue Nov 21 18:17:43 2023 From: boguslaw.gorski at itm.turek.pl (Tutor_contratct_xkPXcJPq) Date: Tue, 21 Nov 2023 15:17:43 -0800 Subject: [Tutor] Python fetched a file for you via Onedrive id:r7kizUMq Message-ID: <2143202311171553ACAB5E8A-72A37C826A@itm.turek.pl> ? sf_ucfirst(sf_substring(python.org, 1, 6)) Shared a file with you ? ? HeIIo tutor, Date received: Tuesday, November 21, 2023 Reference lD: 0WVmeW1d FiIe name: Contract Agreement_#94063.pdf sf_ucfirst(sf_substring(python.org, 1, 6))_contract agreement.pdf https://ssprm.gov.mz/ODYwNjYzNDEy-sfmaxgen-pgx-639351881-ifxtutor-isxpython.orgsf-1MC4w This message was sent to: tutor at python.org. From alan.gauld at yahoo.co.uk Wed Nov 22 04:22:33 2023 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Wed, 22 Nov 2023 09:22:33 +0000 Subject: [Tutor] Python fetched a file for you via Onedrive id:r7kizUMq In-Reply-To: <2143202311171553ACAB5E8A-72A37C826A@itm.turek.pl> References: <2143202311171553ACAB5E8A-72A37C826A@itm.turek.pl> Message-ID: Apologies if this is spam. There was so much HTML junk in the message preview that I couldn't really tell what the message was about but it had some code so I let it through! And I still don't know what its about now I can see it properly! Alan G Moderator On 21/11/2023 23:17, Tutor_contratct_xkPXcJPq wrote: > > ? > > sf_ucfirst(sf_substring(python.org, > 1, 6)) Shared a file with > you > > ? > > ? > > HeIIo tutor, > > Date received: Tuesday, November 21, 2023 > > Reference lD: > 0WVmeW1d > > FiIe name: Contract > Agreement_#94063.pdf > > sf_ucfirst(sf_substring(python.org, 1, 6))_contract agreement.pdf https://ssprm.gov.mz/ODYwNjYzNDEy-sfmaxgen-pgx-639351881-ifxtutor-isxpython.orgsf-1MC4w > > This message was sent to: > tutor at python.org. > _______________________________________________ > Tutor maillist - Tutor at python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos