Cómo usar tkinter

Ejemplos de código

7
0

python tkinter

import tkinter as tk

obj = tk.Tk() # Creates a tkinter object
label = tk.Label(obj, text="This is a text button")
4
0

tutorial de tkinter

# check this code first.
from tkinter import *

app = Tk()
# The title of the project
app.title("The title of the project")
# The size of the window
app.geometry("400x400")

# Defining a funtion
def c():
    # Label
    m = Label(app, text="Text")
    m.pack()


# Button
l = Button(app, text="The text of the Butoon", command=c)
# Packing the Button
l.pack()
app.mainloop()
# Quick Note : 
# When you put a command you should not use parentheses
# l = Button(app, text="The text of the Butoon", command=c)
# l = Button(app, text="The text of the Butoon", command=c())
2
0

tutorial de tkinter

# Python 3.x
import tkinter
top = tkinter.Tk()
# Code to add widgets will go here...
top.mainloop()

# I recommend creating each tkinter window as a child class to a frame.
# This keeps all methods related to the window encapsulated, and makes
# your code alot more understandable and readable :)
1
0

ejemplo de python con 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()
1
0

tutorial de tkinter python

button = tk.Button(
    text="Click me!",
    width=25,
    height=5,
    bg="blue",
    fg="yellow",
)

En otros idiomas

Esta página está en otros idiomas

Русский
..................................................................................................................
English
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Slovenský
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................