xxxxxxxxxx
import tkinter as tk #import the tkinter module as tk
core = tk.Tk() #makes the core (or root)
mylabel = tk.Label(core, text="Hello world!") #makes a label
mylabel.grid(row=0, column=1) #places the object in a virtual grid
tk.Pack() #Pack the object(s)
core.mainloop()#Make the application a loop (needed)
xxxxxxxxxx
import tkinter as tk
# creates and runs an instance of the window
window = tk.Tk()
#makes the size of the widow
window.geometry("600x400")
#sets a title for the screen
window.title("intercode")
# creating a new label and adding a text to the window
new_label=tk.Label(window,text='Enter your height in feet\n')
new_label.pack()
#creates a entrybox to add words to window
entry_label=tk.Entry(window)
entry_label.pack()
# defines results as string var
results= tk.StringVar(window)
#creating a results label
result_lable=tk.Label(window,textvariable=results)
result_lable.pack()
def callbackfunct():
height = entry_label.get()
try:
height= float(height)
except ValueError:
results.set("\nPlease Enter Number.")
converted_height=0.0606061*float(height)
# rounds to decimal places
converted_height=round(converted_height,3)
results.set(f"\nYou are converted height |{converted_height}| tall.")
print(f"inputs .*>|{converted_height}|<*. ")
# deletes the text in the text box
entry_label.delete(0,tk.END)
# creating a button with a command
buttonez = tk.Button(text="Submit", command=callbackfunct)
buttonez.pack()
window.mainloop()
xxxxxxxxxx
from tkinter import * # import tkinter
window = Tk() #create a window
window.mainloop() #update window
xxxxxxxxxx
from tkinter import *
from tkinter import ttk
root = Tk()
frm = ttk.Frame(root, padding=10)
frm.grid()
ttk.Label(frm, text="Hello World!").grid(column=0, row=0)
ttk.Button(frm, text="Quit", command=root.destroy).grid(column=1, row=0)
root.mainloop()
xxxxxxxxxx
import tkinter as tk
r = tk.Tk()
r.title('Counting Seconds')
button = tk.Button(r, text='Stop', width=25, command=r.destroy)
button.pack()
r.mainloop()
xxxxxxxxxx
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()
xxxxxxxxxx
import tkinter as tk
# Create a new window
window = tk.Tk()
# Set the window title
window.title("My GUI")
# Create a label
label = tk.Label(window, text="Hello, World!")
# Add the label to the window
label.pack()
# Start the event loop
window.mainloop()
xxxxxxxxxx
import tkinter as tk
import tkinter.ttk as ttk
def check_credentials(username, password):
# Placeholder function to check username and password
# Returns True if the given username and password match, False otherwise
return username == "admin" and password == "password"
def on_submit():
# Retrieve the username and password entered by the user
username = username_entry.get()
password = password_entry.get()
# Check if the entered credentials are correct
if check_credentials(username, password):
message = "Login successful"
else:
message = "Incorrect username or password"
# Update the result label with the outcome of the login attempt
result_label.config(text=message)
# Create the main window
root = tk.Tk()
root.title("Login")
root.config(padx=10, pady=10)
# Create the widgets
username_label = ttk.Label(root, text="Username:") # Label for the username entry
username_entry = ttk.Entry(root) # Entry widget for the username
password_label = ttk.Label(root, text="Password:") # Label for the password entry
password_entry = ttk.Entry(root, show="*") # Entry widget for the password, with asterisks to hide the input
submit_button = ttk.Button(root, text="Submit", command=on_submit) # Submit button to trigger the login attempt
result_label = ttk.Label(root) # Label to display the result of the login attempt
# Position the widgets in the grid
username_label.grid(row=0, column=0, sticky="W")
username_entry.grid(row=0, column=1)
password_label.grid(row=1, column=0, sticky="W")
password_entry.grid(row=1, column=1)
submit_button.grid(row=2, column=0, columnspan=2, pady=10)
result_label.grid(row=3, column=0, columnspan=2)
# Start the main event loop
root.mainloop()
xxxxxxxxxx
from tkinter import *
#This is a simple app with buttons
#I hope you like it! :)
root = Tk()
root.geometry("400x400")
root.config(bg="gray")
root.
title ="Cool App"
root.title(" ")
def Do():
global title
Value = Placeholder.get()
title = Value
root.title(title)
Placeholder = Entry(root,font=("serif",14))
Placeholder.pack()
Placeholder.focus()
Settings = Button(root,text="Settings",font="14")
Settings.place(x=350,y=330)
EditName = Button(root,text="Edit this App Name",bg="blue",activebackground="blue",font=("serif",15),command=Do)
EditName.pack()
root.mainloop()