1# check this code first.
2from tkinter import *
3
4app = Tk()
5# The title of the project
6app.title("The title of the project")
7# The size of the window
8app.geometry("400x400")
9
10# Defining a funtion
11def c():
12 # Label
13 m = Label(app, text="Text")
14 m.pack()
15
16
17# Button
18l = Button(app, text="The text of the Butoon", command=c)
19# Packing the Button
20l.pack()
21app.mainloop()
22# Quick Note :
23# When you put a command you should not use parentheses
24# l = Button(app, text="The text of the Butoon", command=c)
25# l = Button(app, text="The text of the Butoon", command=c())
1from tkinter import * #import
2
3def main():
4 screen = Tk()#initialize
5 screen.geomerty("num1xnum2") #pixels
6 screen.title("Title")
7 screen.cofigure(bg = 'grey')#hex colors or normal colors
8
9 screen.mainloop()
10main()#call
1import tkinter as tk
2root = tk.Tk()
3root.title("my title")
4root.geometry('200x150')
5root.configure(background='black')
6
7# enter widgets here
8
9root.mainloop()
1Make your event handler a lambda function, which calls your command() - in this case get_dir()
2- with whatever arguments you want:
3
4xbBrowse = Button(frameN, text="Browse...", font=fontReg, command=lambda : self.get_dir(xbPath))
1# App python gui
2
3import tkinter as tk
4import webbrowser as wb
5
6
7def Facebook():
8 wb.open('facebook.com')
9
10
11def Instagram():
12 wb.open('instagram.com')
13
14
15def Twitter():
16 wb.open('twitter.com')
17
18
19def Youtube():
20 wb.open('youtube.com')
21
22
23def Google():
24 wb.open('google.com')
25
26
27window = tk.Tk()
28window.title('Browser')
29
30google = tk.Button(window, text='Google', command=Google)
31youtube = tk.Button(window, text='Youtube', bg='red', fg='white', command=Youtube)
32twitter = tk.Button(window, text='Twitter', bg='powder blue', fg='white', command=Twitter)
33Instagram = tk.Button(window, text='Instagram', bg='white', fg='black', command=Instagram)
34facebook = tk.Button(window, text='Facebook', bg='blue', fg='white', command=Facebook)
35facebook.pack()
36Instagram.pack()
37twitter.pack()
38youtube.pack()
39google.pack()
40
41window.mainloop()
1from tkinter import *
2import time, datetime
3from time import gmtime, strftime
4
5root = Tk()
6
7# Window Attributes
8root.overrideredirect(1)
9root.wm_attributes("-transparentcolor", "gray99")
10
11running = True
12
13# close window
14def close(event):
15 global running
16 running = False
17
18root.bind('<Escape>', close)
19
20screen_width = root.winfo_screenwidth()
21screen_height = root.winfo_screenheight()
22
23timeframe = Frame(root, width=screen_width, height=screen_height, bg="gray99")
24timeframe.grid(row=0,column=0)
25
26tkintertime = StringVar()
27timelabel = Label(timeframe, textvariable=tkintertime, fg="white", bg="gray99", font=("NovaMono", 40))
28timelabel.place(y=screen_height/2 - 60, x=screen_width/2, anchor="center")
29
30tkinterdate = StringVar()
31datelabel = Label(timeframe, textvariable=tkinterdate, fg="white", bg="gray99", font=("Bahnschrift", 15))
32datelabel.place(y=screen_height/2 + 60, x=screen_width/2, anchor="center")
33
34
35while running:
36 tkintertime.set(value=strftime("%H:%M:%S"))
37 tkinterdate.set(value=strftime("%A, %e %B"))
38 root.update_idletasks()
39 root.update()
40 time.sleep(1)