用元組接收返回的多個陣列
class p(object):
def __init__(self):
(self.x,self.y)=self.xdxx()
print(self.x)
def xdxx(self):
a=[1,4,5,8,5]
b=[4,5,8,9,9]
return a,b
t=p()
(x,y)=xdxx()
print(x)
複製程式碼
n=int(input())
print(n)
#這種做法完全OK
複製程式碼
num = 6
l1=[1,2,3,4,5,6]
l2=[7,8,9,5,4,3]
l=[]#不要忘記寫
for i in range(num):
l.append(str(l1[i])+' '+str(l2[i]))
print(l)
#可以執行
複製程式碼
獲取entry的內容時踩過的坑
from tkinter import *
def submit():
print(u.get())
p.set(u.get())
root = Tk()
root.title("測試")
frame = Frame(root)
frame.pack(padx=8, pady=8, ipadx=4)
lab1 = Label(frame, text="獲取:")
lab1.grid(row=0, column=0, padx=5, pady=5, sticky=W)
#繫結物件到Entry
u = StringVar()
ent1 = Entry(frame, textvariable=u)
ent1.grid(row=0, column=1, sticky='ew', columnspan=2)
print(u.get())
lab2 = Label(frame, text="顯示:")
lab2.grid(row=1, column=0, padx=5, pady=5, sticky=W)
p = StringVar()
ent2 = Entry(frame, textvariable=p)
ent2.grid(row=1, column=1, sticky='ew', columnspan=2)
button = Button(frame, text="登入", command=submit, default='active')
button.grid(row=2, column=1)
lab3 = Label(frame, text="")
lab3.grid(row=2, column=0, sticky=W)
button2 = Button(frame, text="退出", command=quit)
button2.grid(row=2, column=2, padx=5, pady=5)
#以下程式碼居中顯示視窗
root.update_idletasks()
x = (root.winfo_screenwidth() - root.winfo_reqwidth()) / 2
y = (root.winfo_screenheight() - root.winfo_reqheight()) / 2
root.geometry("+%d+%d" % (x, y))
root.mainloop()
複製程式碼