Re: Is Programming Obsolete?

Liste des GroupesRevenir à c misc 
Sujet : Re: Is Programming Obsolete?
De : ram (at) *nospam* zedat.fu-berlin.de (Stefan Ram)
Groupes : comp.misc
Date : 07. Apr 2024, 19:51:32
Autres entêtes
Organisation : Stefan Ram
Message-ID : <rewrite-20240407194650@ram.dialup.fu-berlin.de>
References : 1 2
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.

Date Sujet#  Auteur
7 Apr 24 * Is Programming Obsolete?47Ben Collver
7 Apr 24 +- Re: Is Programming Obsolete?1Stefan Ram
7 Apr 24 +* Re: Is Programming Obsolete?28Rich
7 Apr 24 i+* Re: Is Programming Obsolete?3Stefan Ram
7 Apr 24 ii+- Re: Is Programming Obsolete?1Stefan Ram
7 Apr 24 ii`- Re: Is Programming Obsolete?1Stefan Ram
7 Apr 24 i+* Re: Is Programming Obsolete?4candycanearter07
8 Apr 24 ii`* Re: Is Programming Obsolete?3Lawrence D'Oliveiro
8 Apr 24 ii `* Re: Is Programming Obsolete?2candycanearter07
8 Apr 24 ii  `- Re: Is Programming Obsolete?1Lawrence D'Oliveiro
8 Apr 24 i+* Re: Is Programming Obsolete?16Lawrence D'Oliveiro
8 Apr 24 ii+* Re: Is Programming Obsolete?9candycanearter07
8 Apr 24 iii`* Re: Is Programming Obsolete?8Lawrence D'Oliveiro
8 Apr 24 iii `* Re: Is Programming Obsolete?7candycanearter07
9 Apr 24 iii  `* Re: Is Programming Obsolete?6Lawrence D'Oliveiro
9 Apr 24 iii   `* Re: Is Programming Obsolete?5candycanearter07
10 Apr 24 iii    `* Re: Is Programming Obsolete?4Lawrence D'Oliveiro
10 Apr 24 iii     `* Re: Is Programming Obsolete?3candycanearter07
11 Apr 24 iii      `* Re: Is Programming Obsolete?2Lawrence D'Oliveiro
11 Apr 24 iii       `- Re: Is Programming Obsolete?1candycanearter07
8 Apr 24 ii+* Re: Is Programming Obsolete?4Rich
9 Apr 24 iii`* Re: Is Programming Obsolete?3Lawrence D'Oliveiro
9 Apr 24 iii `* Re: Is Programming Obsolete?2Rich
9 Apr 24 iii  `- Re: Is Programming Obsolete?1Lawrence D'Oliveiro
11 Apr 24 ii`* Re: Is Programming Obsolete?2Scott Dorsey
12 Apr 24 ii `- Re: Is Programming Obsolete?1Lawrence D'Oliveiro
8 Apr 24 i`* Re: Is Programming Obsolete?4Ben Collver
8 Apr 24 i `* Re: Is Programming Obsolete?3Lawrence D'Oliveiro
8 Apr 24 i  `* Re: Is Programming Obsolete?2Ben Collver
9 Apr 24 i   `- Re: Is Programming Obsolete?1Lawrence D'Oliveiro
7 Apr 24 +* Re: Is Programming Obsolete?3Stefan Ram
7 Apr 24 i+- Re: Is Programming Obsolete?1Stefan Ram
8 Apr 24 i`- Re: Is Programming Obsolete?1Rich
7 Apr 24 +* Re: Is Programming Obsolete?2Lawrence D'Oliveiro
8 Apr 24 i`- Re: Is Programming Obsolete?1Computer Nerd Kev
12 May 24 `* Re: Is Programming Obsolete?12Scott Dorsey
12 May 24  +- Re: Is Programming Obsolete?1David LaRue
12 May 24  +* Re: Is Programming Obsolete?4D
12 May 24  i+* Re: Is Programming Obsolete?2Scott Dorsey
13 May 24  ii`- Re: Is Programming Obsolete?1D
13 May 24  i`- Re: Is Programming Obsolete?1Johanne Fairchild
13 May 24  +* Re: Is Programming Obsolete?5Bob Eager
13 May 24  i+* Re: Is Programming Obsolete?2Scott Dorsey
13 May 24  ii`- Re: Is Programming Obsolete?1Bob Eager
13 May 24  i`* Re: Is Programming Obsolete?2Anton Shepelev
14 May 24  i `- Re: Is Programming Obsolete?1candycanearter07
13 May 24  `- Re: Is Programming Obsolete?1Johanne Fairchild

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal