คำสั่ง (return) คือ คำสั่งคือที่ใช้สำหรับส่งค่ากลับไป เพื่อให้สามารถนำค่าที่ (return) มาใช้งานต่อได้
โดยในบทความนี้ จะมาทำการ (return) ค่า ตัวแปรในฟังก์ชันให้สามานำค่าของตัวแปรไปใช้ในอีกฟังก์ชัน อื่น ๆ
ให้สามารถใช้ตัวแปรเดียวกันได้ โดยที่ไม่ต้องประกาศเพิ่ม
โค้ด
โค้ด: เลือกทั้งหมด
from tkinter import *
def test0():
a , aa = test1()
print('a=%d'%a)
print('aa=%d'%aa)
def test1():
a = 1
aa = 2
return a , aa
gui = Tk()
gui.geometry("50x50")
Button( text='Login', command=test0).pack()
gui.mainloop()
กด login ผลรัน บทเรียน Python
VDO Tutorial - Python
บทเรียน Python Tensorflow
บทเรียน Python GUI
การใช้งาน Python GUI