In this series, we’ll be leveraging Tkinter, Python’s built-in GUI library, to create a memo app.
Getting Started with the “Hello World” ProgramLet’s begin by exploring how to use Tkinter with the following “Hello World” program outlined in its official documentation.
from tkinter import * from tkinter import ttk root = Tk() frm = ttk.Frame(root, padding=10) frm.grid() ttk.Label(frm, text="Hello World!").grid(column=0, row=0) ttk.Button(frm, text="Quit", command=root.destroy).grid(column=1, row=0) root.mainloop() Upon execution, this script will display a window like the one shown below.
In this article, I’ll show you how to skip the execution of cells in Jupyter Notebook based on certain conditions.
The methods described here are applicable to Google Colaboratory and Kaggle Notebooks.
How to Skip a Cell ExecutionTo skip cell execution, create a custom magic command as follows:
First, create a skip magic command that does nothing.
from IPython.core.magic import register_cell_magic @register_cell_magic def skip(line, cell): return To skip a cell, simply add %%skip at the top line of the cell.
In this installment, we’ll dive deeply into how to add interactive buttons to your chat messages in Discord. Additionally, we’ll explore the variety of responses you can trigger when these buttons are pressed.
Note Given that this article aims to be a comprehensive guide on Discord bot interactions, it’s a bit longer than our previous posts. About Message ComponentsDiscord provides a framework for adding “message components” (or simply “components”), which are interactive elements you can place within chat messages.
Continuing from our last session, we’ll be using discord.ext.commands to add options to our chatbot commands.
(Reference: Documentation)
We’ll add a new ‘category’ option to the ‘quiz’ feature, allowing for quizzes in various categories.
Additionally, we’ll introduce a ’timeout’ option to adjust the time limit for answering questions.
RecapIn our previous article, we refactored the code using discord.py’s extension, discord.ext.commands.
The code for the ‘quiz’ feature, found in commands/quiz.py, is as follows:
In this article, we’ll leverage the discord.ext.commands extension in discord.py
to refactor our somewhat complex on_message function.
RecapThe code up to our last session is as follows:
We added !omikuji and !quiz commands, which made the on_message function somewhat bloated.
import asyncio import json import random import discord class MyClient(discord.Client): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) quiz_file = 'python_problems.en.json' with open(quiz_file) as f: self.quiz_list = json.load(f) async def on_ready(self): """Triggered when connecting to Discord.
In this post, we’ll introduce a method to wait for user replies and leverage it to add a new ‘Quiz’ feature to our chatbot.
A Recap of What We’ve CoveredPreviously, we delved into how to reply to user messages.
We then employed this mechanism to incorporate a ‘fortune-telling’ feature.
import discord import random class MyClient(discord.Client): async def on_ready(self): """Triggered when connecting to Discord.""" print(f'Connected as {self.user}.') async def on_message(self, message: discord.