- Популярные видео
- Авто
- Видео-блоги
- ДТП, аварии
- Для маленьких
- Еда, напитки
- Животные
- Закон и право
- Знаменитости
- Игры
- Искусство
- Комедии
- Красота, мода
- Кулинария, рецепты
- Люди
- Мото
- Музыка
- Мультфильмы
- Наука, технологии
- Новости
- Образование
- Политика
- Праздники
- Приколы
- Природа
- Происшествия
- Путешествия
- Развлечения
- Ржач
- Семья
- Сериалы
- Спорт
- Стиль жизни
- ТВ передачи
- Танцы
- Технологии
- Товары
- Ужасы
- Фильмы
- Шоу-бизнес
- Юмор
Returning text from a function when clicking a button Python Tkinter
Hello everyone! I hope this video has helped solve your questions and issues. This video is shared because a solution has been found for the question/problem. I create videos for questions that have solutions. If you have any other issues, feel free to reach out to me on Instagram: https://www.instagram.com/ky.emrah
Below, you can find the text related to the question/problem. In the video, the question will be presented first, followed by the answers. If the video moves too fast, feel free to pause and review the answers. If you need more detailed information, you can find the necessary sources and links at the bottom of this description. I hope this video has been helpful, and even if it doesn't directly solve your problem, it will guide you to the source of the solution. I'd appreciate it if you like the video and subscribe to my channel!Returning text from a function when clicking a button Python Tkinter
I'm working on an exercise and I'm learning how to use Tkinter.
I manage to get my code working but I can't figure out a way of making it work the way I want.
I want the joke to be printed and then appended to the messagebox, rather than having it displayed in the terminal.
Any pointers?
Couldn't find an answer in the similar questions asked.
I've tried using the variable inside the messagebox but it just opens an empty box.
import pyjokes
from tkinter import ttk
from tkinter import messagebox
def get_funny():
joke1 = print(pyjokes.get_joke())
messagebox.showinfo()
root = tk.Tk()
title = root.title("Free Jokes")
window_width = 300
window_height = 200
#get screen dimensions
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
#find the center point
center_x = int(screen_width/2 - window_width / 2)
center_y = int(screen_height/2 - window_height / 2)
root.geometry(f"{window_width}x{window_height}+{center_x}+{center_y}")
#root.resizable(False,False) make the window a fixed size
message = tk.Label(root, text="Fun Box 3000")
message.pack()
#include funny_button = ttk.Button(
root,
text="Click for funny",
command=get_funny
)
funny_button.pack(
ipadx=5,
ipady=5,
expand=True
)
root.mainloop()```
import pyjokes
from tkinter import ttk
from tkinter import messagebox
def get_funny():
joke1 = print(pyjokes.get_joke())
messagebox.showinfo()
root = tk.Tk()
title = root.title("Free Jokes")
window_width = 300
window_height = 200
#get screen dimensions
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
#find the center point
center_x = int(screen_width/2 - window_width / 2)
center_y = int(screen_height/2 - window_height / 2)
root.geometry(f"{window_width}x{window_height}+{center_x}+{center_y}")
#root.resizable(False,False) make the window a fixed size
message = tk.Label(root, text="Fun Box 3000")
message.pack()
#include funny_button = ttk.Button(
root,
text="Click for funny",
command=get_funny
)
funny_button.pack(
ipadx=5,
ipady=5,
expand=True
)
root.mainloop()```
Tags: python,tkinter,buttonSource of the question:
https://stackoverflow.com/questions/78996593
Question and source license information:
https://meta.stackexchange.com/help/licensing
https://stackoverflow.com/
Видео Returning text from a function when clicking a button Python Tkinter канала Emrah KAYA
Below, you can find the text related to the question/problem. In the video, the question will be presented first, followed by the answers. If the video moves too fast, feel free to pause and review the answers. If you need more detailed information, you can find the necessary sources and links at the bottom of this description. I hope this video has been helpful, and even if it doesn't directly solve your problem, it will guide you to the source of the solution. I'd appreciate it if you like the video and subscribe to my channel!Returning text from a function when clicking a button Python Tkinter
I'm working on an exercise and I'm learning how to use Tkinter.
I manage to get my code working but I can't figure out a way of making it work the way I want.
I want the joke to be printed and then appended to the messagebox, rather than having it displayed in the terminal.
Any pointers?
Couldn't find an answer in the similar questions asked.
I've tried using the variable inside the messagebox but it just opens an empty box.
import pyjokes
from tkinter import ttk
from tkinter import messagebox
def get_funny():
joke1 = print(pyjokes.get_joke())
messagebox.showinfo()
root = tk.Tk()
title = root.title("Free Jokes")
window_width = 300
window_height = 200
#get screen dimensions
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
#find the center point
center_x = int(screen_width/2 - window_width / 2)
center_y = int(screen_height/2 - window_height / 2)
root.geometry(f"{window_width}x{window_height}+{center_x}+{center_y}")
#root.resizable(False,False) make the window a fixed size
message = tk.Label(root, text="Fun Box 3000")
message.pack()
#include funny_button = ttk.Button(
root,
text="Click for funny",
command=get_funny
)
funny_button.pack(
ipadx=5,
ipady=5,
expand=True
)
root.mainloop()```
import pyjokes
from tkinter import ttk
from tkinter import messagebox
def get_funny():
joke1 = print(pyjokes.get_joke())
messagebox.showinfo()
root = tk.Tk()
title = root.title("Free Jokes")
window_width = 300
window_height = 200
#get screen dimensions
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
#find the center point
center_x = int(screen_width/2 - window_width / 2)
center_y = int(screen_height/2 - window_height / 2)
root.geometry(f"{window_width}x{window_height}+{center_x}+{center_y}")
#root.resizable(False,False) make the window a fixed size
message = tk.Label(root, text="Fun Box 3000")
message.pack()
#include funny_button = ttk.Button(
root,
text="Click for funny",
command=get_funny
)
funny_button.pack(
ipadx=5,
ipady=5,
expand=True
)
root.mainloop()```
Tags: python,tkinter,buttonSource of the question:
https://stackoverflow.com/questions/78996593
Question and source license information:
https://meta.stackexchange.com/help/licensing
https://stackoverflow.com/
Видео Returning text from a function when clicking a button Python Tkinter канала Emrah KAYA
Комментарии отсутствуют
Информация о видео
12 февраля 2025 г. 23:36:58
00:01:18
Другие видео канала
