1+ ########## Intro to GUI App Development ##########
2+
3+
4+ #There are numerous "frameworks" you can use to build a user interface with Python
5+ #This is to build desktop applications.
6+ #Although there may be some debate on which is best,
7+ #you can probably get the job done with any
8+ #tkinter is build it. So that's what we are going to learn first.
9+
10+ #Seperation between functionality and UI is ideal
11+ #Because of this, we try to keep logic in the UI code minimal
12+ #We can make this easier by creating an SDK to work with the Db (as we did)
13+ #Long term goal is to actually create an API we can consume...
14+ #We'll get into this, but essentially we can have the same backend for:
15+ # Desktop app
16+ # CLI
17+ # Web App
18+ # Mobile App
19+ # Etc...
20+
21+ #For now we are going to use the SDK, build out a UI, and then later an API
22+
23+ """
24+ #Getting started
25+ #Because tkinter is built in, we don't have to download or install anything.
26+ #We just import it:
27+ import tkinter
28+ tk = tkinter.Tk() #This is the start up code just to get a window
29+ #We can modify the window title like so:
30+ tk.title("This is a Title")
31+ tk.mainloop() #This will "start" the application.
32+ print("This will wait")
33+ """
34+
35+ #Let's build a small application:
36+
37+ from random import randint
38+ import tkinter
39+ from tkinter import messagebox
40+
41+ low = 0
42+ high = 20
43+ rand = randint (low , high )
44+ def check (guess ):
45+ print (guess )
46+ if guess < rand :
47+ #tkinter.messagebox.showinfo("No", "You guessed " + str(guess)).pack
48+ tkinter .Label (tk , text = f"{ guess } is low" ).pack ()
49+ elif guess > rand :
50+ tkinter .Label (tk , text = f"{ guess } is high" ).pack ()
51+ else :
52+ tkinter .messagebox .showinfo ("You win!" , f"{ guess } is correct!" )
53+
54+ tk = tkinter .Tk ()
55+ tk .title ("Guessing Game" )
56+ guess_goal = tkinter .Label (tk , text = f"Guess a number { low } to { high } (inclusive)" )
57+ guess_goal .pack ()
58+ entry = tkinter .Entry (tk )
59+ entry .pack ()
60+ button = tkinter .Button (tk , text = "Take a guess" , command = lambda : check (int (entry .get ())))
61+ button .pack ()
62+ tk .mainloop ()
63+
64+ ########## Tkinter basics ##########
65+ ########## Displaying a List of Data with Tkinter ##########
66+ ########## Removing List Items in Tkinter ##########
67+ ########## Working with SQLlite in Tkinter ##########
68+
69+
70+
71+
72+ """
73+ frame = tkinter.Frame(tk, relief=RIDGE, borderwidth=2)
74+ frame.pack(fill=BOTH,expand=1)
75+ label = tkinter.Label(frame, text="Hello, World")
76+ label.pack(fill=X, expand=1)
77+ button = tkinter.Button(frame,text="Exit",command=tk.destroy)
78+ button.pack(side=BOTTOM)
79+ tk.mainloop()
80+ """
0 commit comments