Basics of I / O screen using tkinter in python3

What I wanted to do

I started using python and knew that I could do various things. I've used it from the command prompt, but can I also use a GUI for input / output tools? First of all, I made a sample for myself.

Why I wrote a simple sample

Searching for "tkinter", "GUI", and "text box" will hit some sites, but suddenly the calculator is running, there is only a part of the explanation for the first time to use tkinter, input only / output Because it was only, I wrote only the part to input and display, which is the basis of the basics

First of all, it worked, so I will record it as a memorandum for myself I will add an explanation as soon as possible </ font> If you can do so far, you can add what you wrote in CUI, enter the search key, and display the result on the GUI as usual, so you can rest assured.

image

tkinter-sample.png

First of all, the source that worked

Either pressing the Enter key or clicking the button will display the entered characters on the output label (the part that initially displays "Output Data"). When actually using it, I think it will be either func or calc

import os, tkinter
def func():      #Operation when the Enter key is pressed
    getvalue = textBox1.get()
    print("in the function =",getvalue)
    textBox1.delete(0,tkinter.END)
    label2["text"] = getvalue
def calc(event):  #Operation when the button is pressed
    getvalue = textBox1.get()
    print("in the function =",getvalue)
    textBox1.delete(0,tkinter.END)
    label2["text"] = getvalue
#Window
root = tkinter.Tk()              #Tk class generation
root.title(u"Window title")  #Screen title
root.geometry("350x150")         #Screen size

#Input / output area
label1 = tkinter.Label(text='InputData')  #Input label
label1.place(x=5,y=5)                     #Label display position
textBox1 = tkinter.Entry(width=5)         #Text box for input
textBox1.place(x=100, y=5)                #Text box position specification
label2 = tkinter.Label(text='OutputData') #Output label
label2.place(x=100,y=50)                  #Label position
textBox1.focus_set()                      #Specify focus on text box
btn = tkinter.Button(text='Go', command=func) #Button creation
btn.pack()
textBox1.bind('<Return>', calc)           #Press Enter to set event

root.mainloop()                           #Show screen

Recommended Posts

Basics of I / O screen using tkinter in python3
python: Basics of using scikit-learn ①
GUI creation in python using tkinter 2
I tried to make a stopwatch using tkinter in python
Python: Basics of image recognition using CNN
About building GUI using TKinter of Python
(Bad) practice of using this in Python
I tried using Bayesian Optimization in Python
I didn't know the basics of Python
Basics of Python ①
Basics of python ①
The basics of running NoxPlayer in Python
Meaning of using DI framework in Python
I tried non-blocking I / O Eventlet behavior in Python
I / O related summary of python and fortran
Summary of Excel operations using OpenPyXL in Python
Basics of Python scraping basics
# 4 [python] Basics of functions
Basics of python: Output
I tried using TradeWave (BitCoin system trading in Python)
Storage I / O notes in Python with Azure Functions
I tried using Python (3) instead of a scientific calculator
Ssh connection memo using ProxyCommand of ssh_config in Python
[Example of Python improvement] I learned the basics of Python on a free site in 2 weeks.
I wrote python in Japanese
Equivalence of objects in Python
[Python] I tried using OpenPose
I understand Python in Japanese!
Implementation of quicksort in Python
What I learned in Python
Translate using googletrans in Python
Using Python mode in Processing
Basics of Python × GIS (Part 1)
I made a simple typing game with tkinter in Python
I made a quick feed reader using feedparser in Python
I measured various methods of interprocess communication in multiprocessing of python3
I made a puzzle game (like) with Tkinter in Python
A memo of writing a basic function in Python using recursion
[Python] I tried collecting data using the API of wikipedia
What beginners learned from the basics of variables in python
I tried to implement blackjack of card game in Python
[Python] Show multiple windows in Tkinter
GUI programming in Python using Appjar
Basics of Python x GIS (Part 3)
Paiza Python Primer 5: Basics of Dictionaries
I couldn't use tkinter with python installed by pyenv of anyenv
Image capture of firefox using python
Precautions when using pit in Python
I compared the calculation time of the moving average written in Python
I made a Line-bot using Python!
Create a python GUI using tkinter
[Python] I wrote the route of the typhoon on the map using folium
Write various forms of phylogenetic tree in Python using ETE Toolkit
I tried to make a regular expression of "amount" using Python
Difference in behavior of transparent Frame made with tkinter in pyinstaller [Python]
Division of timedelta in Python 2.7 series
Removal of haze using Python detailEnhanceFilter
I tried to make a regular expression of "time" using Python
MySQL-automatic escape of parameters in python
Handling of JSON files in Python
Try using LevelDB in Python (plyvel)