
И снова с нами программист Веня вместе с его бесконечными идеями! В этот раз Веня решил сделать
себе электронную телефонную книгу с номерами своих друзей. Но TKinter он так и не выучил, поэтому ему снова нужна наша помощь :) Давайте поможем Вене составить телефонную книгу с номерами четверых его друзей: Вася - 445-241-12 Миша - 442-555-41 Сеня - 448-112-37 Дима - 441-536-52 Нужно сделать так, чтобы Веня выбирал имя друга (здесь поможет Radiobutton), а в Label при нажатии кнопки выводился номер телефона этого человека. Попробуйте у каждой радио-кнопки установить свойство: indicatoron=0 Тогда каждая радиокнопка будет похожа на обыкновенную кнопку:

Ответы на вопрос

Ответ:
Вася:44
Миша:6
сеня:73
Дима: не знаю



To help Venya create an electronic phone book using Tkinter, we can use the Radiobutton widget to allow Venya to select a friend's name, and a Label widget to display the selected friend's phone number when a button is pressed. We can set the `indicatoron` property of each Radiobutton to 0 to make them look like regular buttons.
Here's an example code snippet that demonstrates how to create the phone book:
```python import tkinter as tk
def display_phone_number(): selected_friend = selected_friend_var.get() phone_number = phone_book[selected_friend] phone_number_label.config(text=phone_number)
phone_book = { "Вася": "445-241-12", "Миша": "442-555-41", "Сеня": "448-112-37", "Дима": "441-536-52" }
root = tk.Tk() root.title("Phone Book")
selected_friend_var = tk.StringVar()
for friend in phone_book: tk.Radiobutton(root, text=friend, variable=selected_friend_var, value=friend, indicatoron=0).pack()
phone_number_label = tk.Label(root, text="") phone_number_label.pack()
show_number_button = tk.Button(root, text="Show Number", command=display_phone_number) show_number_button.pack()
root.mainloop() ```
In this code, we first define a function `display_phone_number()` that retrieves the selected friend's name from the `selected_friend_var` variable, looks up their phone number in the `phone_book` dictionary, and updates the `phone_number_label` with the phone number.
We then create a Tkinter window using `tk.Tk()` and set its title to "Phone Book".
Next, we create a `selected_friend_var` variable of type `StringVar()` to store the selected friend's name.
We iterate over the `phone_book` dictionary and create a Radiobutton for each friend. The `text` parameter is set to the friend's name, the `variable` parameter is set to `selected_friend_var`, the `value` parameter is set to the friend's name, and the `indicatoron` parameter is set to 0 to make the Radiobutton look like a regular button.
We create a Label widget `phone_number_label` to display the phone number and initially set its text to an empty string.
Finally, we create a Button widget `show_number_button` with the text "Show Number" and the command `display_phone_number` to call the `display_phone_number()` function when the button is pressed.
We then use the `pack()` method to display the Radiobuttons, Label, and Button in the window.
To run the code, save it to a file with a `.py` extension (e.g., `phone_book.py`) and execute it using a Python interpreter.
When Venya selects a friend's name and clicks the "Show Number" button, the corresponding phone number will be displayed in the Label widget.
I hope this helps Venya create his electronic phone book! Let me know if you have any further questions.


Похожие вопросы
Топ вопросов за вчера в категории Информатика







Последние заданные вопросы в категории Информатика
-
Математика
-
Литература
-
Алгебра
-
Русский язык
-
Геометрия
-
Английский язык
-
Химия
-
Физика
-
Биология
-
Другие предметы
-
История
-
Обществознание
-
Окружающий мир
-
География
-
Українська мова
-
Информатика
-
Українська література
-
Қазақ тiлi
-
Экономика
-
Музыка
-
Право
-
Беларуская мова
-
Французский язык
-
Немецкий язык
-
МХК
-
ОБЖ
-
Психология
-
Физкультура и спорт
-
Астрономия
-
Кыргыз тили
-
Оʻzbek tili