[PYTHON] How to rewrite Tkinter labels

Introduction

With python GUI creation library "tkinter" I was in trouble because I didn't know how to write the process that the label was rewritten when the button was pressed.

I will write the coping method according to the original purpose and content of creating an application that receives the numerical value entered in the text box and outputs the average.

environment

Python 3.6.8

Processing method

When rewriting the label of the variable name words as "rewrited" In the process when the button is pressed

words["text"] = "rewrited"

Just add it.

A more specific explanation, rather than a code example

import tkinter as tk

root = tk.Tk()
root.title(u"Average calculation app")
root.geometry("400x300")


#Processing when the button is pressed

def buttoneffect(event):
    value = textbox.get()
    split_value = value.split(",")
    int_values = list(map(int, split_value))
    average = sum(int_values) / len(int_values)

    textbox.delete(0, tk.END)  #Initialize the contents of the text box
    words4["text"] = "The average value is%s." % average  #Rewrite the contents of the label


#Arrangement of buttons and text boxes

words = tk.Label(text=u"Calculates the average value of the entered values.", font=("", 12))
words.pack()

words2 = tk.Label(text=u"Enter the numbers separated by commas.", font=("", 12))
words2.pack()

textbox = tk.Entry()
textbox.insert(tk.END, "Input this box.")
textbox.place(x=140, y=70)

button = tk.Button(text=u"calculate")
button.bind("<Button-1>", buttoneffect)
button.place(x=150, y=100)

words3 = tk.Label(text=u"Statistical data", font=("", 12))
words3.place(x=50, y=140)

words4 = tk.Label(text=u" ", font=("", 12))  #Empty label used to output mean
words4.place(x=140, y=160)


root.mainloop()

reference

Try using Python's Tkinter https://qiita.com/nnahito/items/ad1428a30738b3d93762

How to change Tkinter label text https://www.delftstack.com/ja/howto/python-tkinter/how-to-change-the-tkinter-label-text/

Recommended Posts

How to rewrite Tkinter labels
How to update Python Tkinter to 8.6
Introduction to Tkinter 1: Introduction
[Python / Tkinter] How to pass arguments to command
How to use tkinter with python in pyenv
How to use xml.etree.ElementTree
How to use Python-shell
How to use tf.data
Scraping 2 How to scrape
How to use Seaboan
How to use image-match
How to use shogun
How to install Python
How to use Pandas 2
How to read PyPI
How to install pip
How to use Virtualenv
How to use numpy.vectorize
How to update easy_install
How to install archlinux
How to use pytest_report_header
Rewrite Python2 code to Python3 (2to3)
How to restart gunicorn
How to install python
How to virtual host
How to debug selenium
How to use partial
How to use Bio.Phylo
How to read JSON
How to use x-means
How to use WikiExtractor.py
How to update Spyder
How to use IPython
How to install BayesOpt
How to use virtualenv
How to use Matplotlib
How to use iptables
How to use TokyoTechFes2015
How to use dictionary {}
How to use Pyenv
How to grow dotfiles
How to use list []
How to use python-kabusapi
"How to count Fukashigi"
How to use OptParse
How to use return
How to install Prover9
How to use dotenv
How to operate NumPy
How to use pyenv-virtualenv
How to use Go.mod
How to use imutils
How to use import
[Python] How to rewrite the table style with python-pptx [python-pptx]
[2020.8 latest] How to install Python
How to estimate kernel density
How to use Qt Designer
[IPython] How to Share IPython Notebook
How to install Python [Windows]
How to use search sorted
[gensim] How to use Doc2Vec