Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

It is necessary to have purpose. -- Alice #1, "I, Mudd", stardate 4513.3


devel / comp.lang.python / (FYI)[tkinter]How is this supposed to work?

SubjectAuthor
o (FYI)[tkinter]How is this supposed to work?Stefan Ram

1
(FYI)[tkinter]How is this supposed to work?

<tkinter-20211030135222@ram.dialup.fu-berlin.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=15869&group=comp.lang.python#15869

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram...@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.python
Subject: (FYI)[tkinter]How is this supposed to work?
Date: 30 Oct 2021 13:19:45 GMT
Organization: Stefan Ram
Lines: 44
Expires: 1 Dec 2021 11:59:58 GMT
Message-ID: <tkinter-20211030135222@ram.dialup.fu-berlin.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de VsxXtlwGczQUIR+UbQxpiAozb7TyWrCreMWNsVdzphAypv
X-Copyright: (C) Copyright 2021 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
Accept-Language: de-DE, en-US, it, fr-FR
 by: Stefan Ram - Sat, 30 Oct 2021 13:19 UTC

Here's a program that creates a window with a label when run
under IDLE, but violates several rules. How is it working then?

import tkinter
tkinter.Label( text="Hello!" ).pack()

.

- It does not create a main window using Tk(),
- neither does it pass a master to the Label class,
- nor does not call "mainloop" at the end;
and still Python runneth it.

Answers:

All widgets use the last main window (root window) opened as
their master when no master is passed as an argument.
(A program should have only one main window, so replace
"the last main window opened" with "the main window" above.)

When no main window was opened, the widget will create a main
window, and then proceed with the step previously mentioned.

IDLE uses tkinter itself and already has a mainloop. So, the
program will use IDLE's mainloop and therefore has not to
create its own mainloop. (Twenty years ago, it was not even
possibly to call your own "mainloop" under IDLE.)

Also note that we have not bound the label to a name.
Yet it is not garbage collected immediately because the
tkinter library has kept a reference to it!

But, the following program is a more general way of coding,
since it can be extended more easily and does not depend on
IDLE:

import tkinter

root_window = tkinter.Tk()
label = tkinter.Label( root_window, text="Hello!" )
label.pack()
tkinter.mainloop()

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor