Python建構constructor視窗%d控制輸出格式

 

控制STYLE的程式碼

<STYLE>
  H1{BORDER:RED SOLID 5PX; PADDING:5PX; BACKGROUND-COLOR:PURPLE;TEXT-ALIGN:CENTER; COLOR:WHITE; BORDER-RADIUS:30PX;}
  PRE{BORDER: BLUE SOLID 1PX;BACKGROUND-COLOR:DARKBLUE;COLOR:WHITE;FONT-WEIGHT:BOLD;}
</STYLE>

單元409使用VS Code

單元409程式碼

from tkinter import * #下載程式碼,從tkinter輸入所有函式
import time
x = ['\U0001F600','\U0001F601','\U0001F602','\U0001F603','\U0001F604']#定義一個串列
y = [] #追蹤特定視窗用途,尚未使用
for i in range(5):
    for j in range(2):
        window = Tk() #建構視窗,名為window建構一個房子
        window.title('大正妹python第%d視窗' % (i+1))
        window.geometry('400x400+%d+%d' % (400*i, j*400))
        b1=Label(window,text=x[i],font='Arial 250 bold').pack()
        time.sleep(1)
        window.update()
        y.append(window)#追蹤特定視窗用途,尚未使用
window.mainloop()

暫存的下一單元使用的程式碼

from tkinter import * #下載程式碼,從tkinter輸入所有函式
import time
x = ['\U0001F600','\U0001F601','\U0001F602','\U0001F603','\U0001F604']#定義一個串列
y = [] #追蹤特定視窗用途,尚未使用
for i in range(5):
    for j in range(2):
        window = Tk() #建構視窗,名為window建構一個房子
        window.title('大正妹python第%d視窗' % (i+1))
        window.geometry('400x400+%d+%d' % (400*i, j*400))
        b1=Label(window,text=x[i],font='Arial 250 bold').pack()
        time.sleep(0.1)
        window.update()
        y.append(window)#追蹤特定視窗用途,尚未使用
win = Tk()
win.title('控制的視窗')
winNo = IntVar(win)
No = [i for i in range(len(y))]
OptionMenu(win, winNo, *No).pack()
Button(win,command=y[int(winNo)].destroy()).pack()
win.mainloop()
 In class-based, object-oriented programming, a constructor (簡稱 ctor) is a special type of function called to create an object. It prepares the new object for use, often accepting arguments that the constructor uses to set required member variables. A constructor resembles an instance method, but it differs from a method in that it has no explicit return type, it is not implicitly inherited and it usually has different rules for scope modifiers. Constructors often have the same name as the declaring class. They have the task of initializing the object's data members and of establishing the invariant of the class, failing if the invariant is invalid. A properly written constructor leaves the resulting object in a valid state. Immutable objects must be initialized in a constructor. Most languages allow overloading the constructor in that there can be more than one constructor for a class, with differing parameters. Some languages take consideration of some special types of constructors. Constructors, which concretely use a single class to create objects and return a new instance of the class, are abstracted by factories, which also create objects but can do so in various ways, using multiple classes or different allocation schemes such as an object pool.

留言

這個網誌中的熱門文章