Answers for "how to use tkinter in python"

6

how to make a tkinter window

from tkinter import *

mywindow = Tk() #Change the name for every window you make
mywindow.title("New Project") #This will be the window title
mywindow.geometry("780x640") #This will be the window size (str)
mywindow.minsize(540, 420) #This will be set a limit for the window's minimum size (int)
mywindow.configure(bg="blue") #This will be the background color

mywindow.mainloop() #You must add this at the end to show the window
Posted by: Guest on September-25-2020
12

how to install tkinter

sudo apt-get install python3-tk
Posted by: Guest on June-09-2020
4

how to install tkinter for python

# for pip and windows, in cmd, write:
pip install tk
Posted by: Guest on June-06-2020
1

how to import tkinter in python

#to import tkinter
from tkinter import * #best way

from tkinter import Tk #another way
Posted by: Guest on November-02-2021
2

python example with tkinter

from tkinter import *
from tkinter import ttk

def calculate(*args):
    try:
        value = float(feet.get())
        meters.set(int(0.3048 * value * 10000.0 + 0.5)/10000.0)
    except ValueError:
        pass

root = Tk()
root.title("Feet to Meters")

mainframe = ttk.Frame(root, padding="3 3 12 12")
mainframe.grid(column=0, row=0, sticky=(N, W, E, S))
root.columnconfigure(0, weight=1)
root.rowconfigure(0, weight=1)

feet = StringVar()
feet_entry = ttk.Entry(mainframe, width=7, textvariable=feet)
feet_entry.grid(column=2, row=1, sticky=(W, E))

meters = StringVar()
ttk.Label(mainframe, textvariable=meters).grid(column=2, row=2, sticky=(W, E))

ttk.Button(mainframe, text="Calculate", command=calculate).grid(column=3, row=3, sticky=W)

ttk.Label(mainframe, text="feet").grid(column=3, row=1, sticky=W)
ttk.Label(mainframe, text="is equivalent to").grid(column=1, row=2, sticky=E)
ttk.Label(mainframe, text="meters").grid(column=3, row=2, sticky=W)

for child in mainframe.winfo_children(): 
    child.grid_configure(padx=5, pady=5)

feet_entry.focus()
root.bind("<Return>", calculate)

root.mainloop()
Posted by: Guest on May-26-2021
4

tkinter

from tkinter import * #import

def main():
  screen = Tk()#initialize
  screen.geomerty("num1xnum2") #pixels
  screen.title("Title")
  screen.cofigure(bg = 'grey')#hex colors or normal colors
  
  screen.mainloop()
main()#call
Posted by: Guest on June-28-2021

Python Answers by Framework

Browse Popular Code Answers by Language