gpt-4o-mini-2024-07-18· OpenAI
WildChat-4.8M (AI2)
give me code of a lunar jokes ith gui
- User
give me code of a lunar jokes ith gui
- Assistant
Sure! Below is a simple Python code that creates a GUI application for displaying lunar-themed jokes using the
tkinterlibrary. To run this code, ensure you havePythoninstalled on your machine. You can also install thePillowlibrary to enhance image support if needed, but it's not required for this basic example.Here's the code:
import tkinter as tk import random # List of lunar jokes jokes = [ "Why did the moon break up with the sun? Because it needed space!", "What do you call a moon that loves to be alone? A 'lone' star!", "How does the moon stay up-to-date with the news? It reads the 'astro-nomical' reports!", "Why did the astronaut break up with his girlfriend? He needed more 'space'!", "What do you call a moon that tells jokes? A 'fun' moon!", "Why did the moon get a job? Because it wanted to make some 'light' work!", "What did the moon say to the Earth? You make me feel so whole!" ] def show_joke(): """Display a random lunar joke.""" joke = random.choice(jokes) joke_label.config(text=joke) # Create the main window root = tk.Tk() root.title("Lunar Jokes") # Create a label to display jokes joke_label = tk.Label(root, text="", wraplength=300, font=("Helvetica", 12), padx=20, pady=20) joke_label.pack() # Create a button to show a joke joke_button = tk.Button(root, text="Tell me a lunar joke!", command=show_joke, bg="lightblue", font=("Helvetica", 12)) joke_button.pack() # Start the Tkinter event loop root.mainloop()Instructions:
-
Copy the above code into a text editor (such as Notepad, VSCode, or PyCharm).
-
Save the file with a
.pyextension (for example,lunar_jokes.py). -
Run the script using Python. You can do this by navigating to the terminal or command prompt, and running:
python lunar_jokes.py
What the Code Does:
- It creates a simple GUI window with a button labeled "Tell me a lunar joke!".
- When the button is clicked, a random lunar joke from the predefined list will be displayed in the GUI.
Feel free to modify the jokes or the GUI design as you wish!
-