2017年10月15日 星期日

Tkinter 9X9 乘法表



from tkinter import *

class Application(Frame):
    """Multiplication Table"""
   
    def __init__(self,master):
        """initialize the frame"""
        Frame.__init__(self,master)
        self.grid()
        
        k=9
        for i in range(k):
            val=i+1
            Label(self,text=val).grid(row=val,column=0)
            Label(self,text=val).grid(row=0,column=val)

        self.btns=[]
        for i in range(k):
            btns=[]
            for j in range(k):
                btns.append(self.create_widgets(i,j))
            self.btns.append(btns)
        
            

    def create_widgets(self,a,b):
        i=(a+1)*(b+1)
        bttn=Button(self,text="?",height=2,width=4)
        def button_action2(event,self=self,i=i):
            return self.button_action(event,i)
        bttn.bind("<ButtonRelease-1>",button_action2)
        bttn.grid(row=a+1,column=b+1)
        bttn.configure(text=str(i),fg='red')
    
root=Tk()
root.title("Multiplication Table")
app=Application(root)

root.mainloop()

沒有留言:

張貼留言

2024年4月24日 星期三 Node-Red Dashboard UI Template + AngularJS 參考 AngularJS教學 --2

 2024年4月24日 星期三 Node-Red Dashboard UI Template + AngularJS 參考 AngularJS教學 --2 AngularJS 實例 <!DOCTYPE html> <html> <head> &...