Run the output code with tkinter, saying "A, pretending to be B" in python

Purpose

It is a memorandum when moving the output code with tkinter as "A and pretending to be B" in python.

Preparation

tkinter is a tool that allows you to build a GUI in Python. I will refer to the following

Event handling with Python Tkinter button Try using Tkinter in Python

code

sample.py


import tkinter as tk
import random

l = ["Apple",
     "Mandarin orange",
     "Strawberry",
     "pineapple",
     "Dragon fruit"]

def bot():
    string1=random.choice(l)
    string2=random.choice(l)

    string=string1+"Pretending to be"+string2

    label = tk.Label(text=string)  #Define label
    x = random.randrange(640)
    y = random.randrange(480)
    label.place(x=x, y=y)                  #Install label

window = tk.Tk()                                        #Define window
window.title("Title")                                   #Set window title
window.geometry("640x480")                              #Set window size

btn = tk.Button(window, text='Pretending to be', command = bot)   #Creating a button
btn.place(x=10, y=10)

window.mainloop()                                       #Put into standby state as main loop

test

ezgif.com-gif-maker.gif

reference

Event handling with Python Tkinter button Try using Tkinter in Python

Recommended Posts

Run the output code with tkinter, saying "A, pretending to be B" in python
Run the output code on the local web server as "A, pretending to be B" in python
Change the standard output destination to a file in Python
Create code that outputs "A and pretending B" in python
I want to be able to run Python in VS Code
Output the contents of ~ .xlsx in the folder to HTML with Python
Run the Python interpreter in a script
[Python] Get the files in a folder with Python
How to use tkinter with python in pyenv
Output in the form of a python array
How to run the practice code of the book "Creating a profitable AI with Python" on Google Colaboratory
Try to solve the traveling salesman problem with a genetic algorithm (Python code)
A solution to the problem that the Python version in Conda cannot be changed
[Python] Created a class to play sin waves in the background with pyaudio
To output a value even in the middle of a cell with Jupyter Notebook
Use libsixel to output Sixel in Python and output a Matplotlib graph to the terminal.
How to get a list of files in the same directory with python
How to convert / restore a string with [] in python
Python Ver. To introduce WebPay with a little code.
How to run tests in bulk with Python unittest
Create a plugin to run Python Doctest in Vim (2)
Create a plugin to run Python Doctest in Vim (1)
A memorandum to run a python script in a bat file
Convert the image in .zip to PDF with Python
I want to work with a robot in python.
[Python] tkinter Code that is likely to be reused
Run a Python file with relative import in PyCharm
[Python] How to output the list values in order
I want to run a quantum computer with Python
How to identify the element with the smallest number of characters in a Python list?
[Note] How to write QR code and description in the same image with python
[Mac] A super-easy way to execute system commands in Python and output the results
It is easy to execute SQL with Python and output the result in Excel
Run Label with tkinter [Python]
I made a simple typing game with tkinter in Python
Output "Draw ferns programmatically" to the drawing process in Python
How to output a document in pdf format with Sphinx
How to use the __call__ method in a Python class
Solution when the image cannot be displayed with tkinter [python]
Probably the easiest way to create a pdf with Python3
Run BNO055 python sample code with I2C (Raspberry Pi 3B)
How to get the last (last) value in a list in Python
I made a puzzle game (like) with Tkinter in Python
I tried to make a stopwatch using tkinter in python
[Python] The first step to making a game with Pyxel
Check the Check button in Tkinter to allow Entry to be edited
Run the program without building a Python environment! !! (How to get started with Google Colaboratory)
I made a class to get the analysis result by MeCab in ndarray with python
Can be used with AtCoder! A collection of techniques for drawing short code in Python!
Recursively get the Excel list in a specific folder with python and write it to Excel.
What seems to be a template of the standard input part of the competition pro in python3
I also tried to imitate the function monad and State monad with a generator in Python
"A book to train programming skills to fight in the world" Python code answer example --1.8 "0" matrix
I wrote a doctest in "I tried to simulate the probability of a bingo game with Python"
Output the key list included in S3 Bucket to a file
How to write when you want to put a number after the group number to be replaced with a regular expression in re.sub of Python
Convert to a string while outputting standard output with Python subprocess
"A book to train programming skills to fight in the world" Python code Solution example --1.6 String compression
"A book to train programming skills to fight in the world" Python code solution example --1.5 One-shot conversion
How to determine the existence of a selenium element in Python
[Python] Create a program to delete line breaks in the clipboard + Register as a shortcut with windows