Python 7 Levels, L7, Unit 76, GUI Interface Example

Powered By EmbedPress

Enumerate:

list_01 = ["one","two","three"]

for index,item in enumerate(list_01):
    print(index,item)

Remote Keyboard:

import tkinter as tk

class Application:

    def __init__(self):
        self.root = tk.Tk()
        self.root.title("Remote Keyboard")
        self.root.geometry("150x150+100+100")
        self.createWidget()

    def createWidget(self):
        self.btn_up = tk.Button(self.root,text="↑",width=4,height=2,bg="red")
        self.btn_up.pack(side = "top")
        self.btn_down = tk.Button(self.root,text="↓",width=4,height=2,bg="red")
        self.btn_down.pack(side = "bottom")
        self.btn_left = tk.Button(self.root,text="←",width=4,height=2,bg="red")
        self.btn_left.pack(side = "left")
        self.btn_right = tk.Button(self.root,text="→",width=4,height=2,bg="red")
        self.btn_right.pack(side = "right")
        
    def run(self):
        self.root.mainloop()

app = Application()
app.run()

Poker Game:

import tkinter as tk

class Application:
    def __init__(self):
        self.root = tk.Tk()
        self.root.title("Poker")
        self.root.geometry("600x270+200+300")
        self.createWidget()

    def createWidget(self):
        global photos
        photos = []
        for i in range(10):
            photos.append(tk.PhotoImage(file="poker/poker"+str(i+1)+".gif"))

        for i in range(10):
            self.pokers = tk.Label(self.root,image=photos[i])
            self.pokers.place(x=10+i*40,y=50)
        
    def run(self):
        self.root.mainloop()


app = Application()
app.run()

Calculator:

import tkinter as tk

class Application:
    def __init__(self):
        self.root = tk.Tk()
        self.root.title("Calculator")
        self.root.geometry("150x220+200+300")
        self.createWidget()


    def createWidget(self):
        self.frame = tk.Frame(self.root)
        self.frame.pack()

        self.entry = tk.Entry(self.frame)
        self.entry.grid(row=0,column=0,columnspan=4,pady=10)

        btnText = (("MC","M+","M-","MR"),
                   ("C","±","/","×"),
                   ("7","8","9","-"),
                   ("4","5","6","+"),
                   ("1","2","3","="),
                   ("0","."))

        self.btn = []
        for r in btnText:
            b = []
            for c in r:
                b.append(tk.Button(self.frame,text = c,width=1))
            self.btn.append(b)

        for r in range(len(self.btn)):
            for c in range(len(self.btn[r])):
                if r == 4 and c == 3:
                    self.btn[r][c].grid(row=r+1,column=c,rowspan = 2,\
                                        sticky="nswe")
                elif r == 5 and c == 0:
                    self.btn[r][c].grid(row=r+1,column=c,columnspan = 2,\
                                        sticky="nswe")
                elif r == 5 and c == 1:
                    self.btn[r][c].grid(row=r+1,column=c+1,\
                                        sticky="nswe")
                else:
                    self.btn[r][c].grid(row=r+1,column=c,sticky="nswe")

    def run(self):
        self.root.mainloop()
        


app = Application()
app.run()

Homework

import tkinter as tk

class Application:

    def __init__(self):
        self.root = tk.Tk()
        self.root.title("Banking System")
        self.root.geometry("300x180+200+100")
        self.createWidget()

    def createWidget(self):
        self.frame = tk.Frame(self.root)
        self.frame.pack()
        self.btn_01 = tk.Button(self.frame,text="Deposit",width=8,height=2).grid(row=0,column=0)
        self.btn_02 = tk.Button(self.frame,text="Withdraw",width=8,height=2).grid(row=1,column=0)
        self.btn_03 = tk.Button(self.frame,text="Balance",width=8,height=2).grid(row=2,column=0)
        self.entry = tk.Entry(self.frame).grid(row=0,column=1,\
                                                        rowspan=2,columnspan=2,sticky="nsew")
        self.label_01 = tk.Label(self.frame,text="Information").grid(row=2,column=1,columnspan=2)
        self.btn_04 = tk.Button(self.frame,text="Mortgate",width=8,height=2).grid(row=0,column=3)
        self.btn_05 = tk.Button(self.frame,text="Transfer",width=8,height=2).grid(row=1,column=3)
        self.btn_06 = tk.Button(self.frame,text="Investment",width=8,height=2).grid(row=2,column=3)

        self.btn_07 = tk.Button(self.frame,text="Confim",width=8,height=1).grid(row=3,column=0,columnspan=2,sticky="we")
        self.btn_08 = tk.Button(self.frame,text="Cancel",width=8,height=1).grid(row=3,column=2,columnspan=2,sticky="we")
        
    def run(self):
        self.root.mainloop()

app = Application()
app.run()

dahan1999

1 Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts