input tkinter code example

Example 1: take input tkinter in python 3

import tkinter as tk

def show_entry_fields():
    print("First Name: %s\nLast Name: %s" % (e1.get(), e2.get()))
    e1.delete(0, tk.END)
    e2.delete(0, tk.END)

master = tk.Tk()
tk.Label(master, text="First Name").grid(row=0)
tk.Label(master, text="Last Name").grid(row=1)

e1 = tk.Entry(master)
e2 = tk.Entry(master)
e1.insert(10, "Miller")
e2.insert(10, "Jill")

e1.grid(row=0, column=1)
e2.grid(row=1, column=1)

tk.Button(master, 
          text='Quit', 
          command=master.quit).grid(row=3, 
                                    column=0, 
                                    sticky=tk.W, 
                                    pady=4)
tk.Button(master, text='Show', command=show_entry_fields).grid(row=3, 
                                                               column=1, 
                                                               sticky=tk.W, 
                                                               pady=4)

master.mainloop()

tk.mainloop()

Example 2: tkinter entry

from tkinter import *
root = Tk()
entry = Entry(root)
print(entry.get()) # Would print entry data in CL

Example 3: make tkinter label and input

there was 2 "=" here V you only need one
example3 = Entry(root, width=10, font="Calibri 10")
example4 = Label(root, width=10, font="Calibri 10")

Example 4: read value from entry tkinter

#ent is the name of the Entry
s = ent.get()

Example 5: how to create a enter box in tkinter

canvas1 = tk.Canvas(root, width = 400, height = 300)
canvas1.pack()