Deutsch English Français Italiano |
<rewrite-20240407194650@ram.dialup.fu-berlin.de> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!weretis.net!feeder8.news.weretis.net!fu-berlin.de!uni-berlin.de!not-for-mail From: ram@zedat.fu-berlin.de (Stefan Ram) Newsgroups: comp.misc Subject: Re: Is Programming Obsolete? Date: 7 Apr 2024 18:51:32 GMT Organization: Stefan Ram Lines: 82 Expires: 1 Feb 2025 11:59:58 GMT Message-ID: <rewrite-20240407194650@ram.dialup.fu-berlin.de> References: <slrnv15e4i.rk6.bencollver@svadhyaya.localdomain> <tkinter-20240407181832@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 /AfL39Y0PlIcIrD3hgN7rgzfUuvjnPk7VsxTf3+8JPSmUm Cancel-Lock: sha1:Tf+zrlXium22TVwwqeUEWRfA8Ok= sha256:uldm0n+IN68uHms6KRcmFtzBO/Svl2CQtQFdIWcXqkI= X-Copyright: (C) Copyright 2024 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 Bytes: 3686 ram@zedat.fu-berlin.de (Stefan Ram) wrote or quoted: >import tkinter >tkinter.Label( text="Hi! What's your name?" ).pack() >entry=tkinter.Entry() >entry.pack() >button = tkinter.Button( text="Ok" ) >def ok(): tkinter.Label( text="Hi, " + entry.get() + "!" ).pack() >button.pack() >button.config( command=ok ) >tkinter.mainloop() It can be rewritten to look a bit smaller and nicer: from tkinter import * Label( text="Hi! What's your name?" ).pack() entry = Entry(); entry.pack() def ok(): Label( text="Hi, " + entry.get() + "!" ).pack() Button( text="Ok", command=ok ).pack() mainloop() Now let me ask the Chatbot! |Chatbot, please write a tiny tkinter program to ask the user |for his name and then greet him using his name. Answer (The rest of my post is what the Chatbot answered): |## Tiny Tkinter Program to Greet the User | |Here's a simple Tkinter program that asks the user for their |name and then greets them: | |python |import tkinter as tk | |def greet(): | name = name_entry.get() | greeting_label.config(text=f"Hello, {name}!") | |root = tk.Tk() |root.title("Greeting App") | |name_label = tk.Label(root, text="What's your name?") |name_label.pack() | |name_entry = tk.Entry(root) |name_entry.pack() | |greet_button = tk.Button(root, text="Greet Me", command=greet) |greet_button.pack() | |greeting_label = tk.Label(root, text="") |greeting_label.pack() | |root.mainloop() | |Here's how the program works: | |1. The `greet()` function is defined, which retrieves the |user's name from the `name_entry` widget and updates the |`greeting_label` with a personalized greeting. | |2. The main Tkinter window is created with the title "Greeting |App". | |3. A label is added to prompt the user for their name. | |4. An entry widget is added to allow the user to input their |name. | |5. A button is added with the text "Greet Me", which calls the |`greet()` function when clicked. | |6. A label is added to display the greeting. | |7. The `mainloop()` function is called to start the Tkinter |event loop and display the application. | |When the user enters their name and clicks the "Greet Me" |button, the program will display a personalized greeting.