โดย ธวัชชัย แสนหาญ » 06/02/2019 6:28 pm
สอบถามการ ผูกฟังก์ชัน ข้ามไพล์ ด้วยโมดูล Tkinter
ผมได้ทำการสร้างไฟล์ python เพื่อทำหน้า window from GUI แล้วต้องการสร้างปุ่มให้มีความสามารถ
กดปุ่มแล้วฟังก์ชันที่อยู่ อีกไฟล์หนึ่ง ทำงาน หรือ(ปุ่มผูกฟังก์ชัน)
ผมได้ทำการ import ไฟล์ให้สามารถเรียกใช้ ฟังก์ชัน ของ อีกไฟล์หนึ่งได้แล้ว แต่ไม่สามารถ สั่งให้อีกไฟล์ Run ได้
มันแจ้งErrorว่า
AttributeError: 'Event' object has no attribute 'categories_check_Add'
บรรทัดที่Error
ข้อความที่Error
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\ter\AppData\Local\Programs\Python\Python36\lib\tkinter\__init__.py", line 1705, in __call__
return self.func(*args)
File "D:/Python selenium_mt27/python_test/Mt27/selenium_moozii/GUI_MooZii Cart_01.py", line 20, in Case_Add_Categories
test=self.categories_check_Add()
AttributeError: 'Event' object has no attribute 'categories_check_Add'
โค้ดทั้งหมด ของตัว หน้า window from
โค้ด: เลือกทั้งหมด
from tkinter import *
from tkinter import messagebox
from TestBotmoozii import MooZiiCart_check , joomla
import sys
class GUI_MooZii(MooZiiCart_check):
def Exit(self):
status=messagebox.askyesno(title='คำยืนยัน',message='ปิดหรือไม่')#ปิดโปรแกรม
if status>0:
print('กด off')
sys.exit()
def Case_Add_Categories(self):
print('Case Add Categories')
test=self.categories_check_Add()
def Case_Add_Products(self):
print('Case Add Products')
def Case_Add_Orders(self):
print('Case Add Orders')
def Case_Add_Clients(self):
print('Case Add Clients')
def Case_Add_Options(self):
print('Options')
def Case_Add_About_us(self):
print('Case Add About us')
def Case_Test_CaseShopping(self):
print('Case Shopping')
# สร่้างหน้าจอ
gui=Tk()
gui.geometry("450x450") #ขนาดframe กว้าง*สูง
gui.title("MooZii Cart") #ชื่อframe
Mlable=Label(text='BACK-END',fg='green',bg='#CCFFFF')
Mlable.grid(row=0)
Mlable=Label(text='FRONT-END',fg='green',bg='#CCFFFF')
Mlable.grid(row=7)
# รายการที่เทส
l1=Label(text='Categories',bg='#80FF80')
l2=Label(text='Product',bg='#80FF80')
l3=Label(text='Orders',bg='#80FF80')
l4=Label(text='Clients',bg='#80FF80')
l5=Label(text='Options',bg='#80FF80')
l6=Label(text='About us',bg='#80FF80')
l8=Label(text='Case Shopping',bg='#80FF80')
l1.grid(row=1)
l2.grid(row=2)
l3.grid(row=3)
l4.grid(row=4)
l5.grid(row=5)
l6.grid(row=6)
l8.grid(row=8)
t1=Button(text='Add',bg='green')
t1.bind('<Button-1>',Case_Add_Categories)
t2=Button(text='Add',bg='green')
t2.bind('<Button-1>',Case_Add_Products)
t3=Button(text='Add',bg='green')
t3.bind('<Button-1>',Case_Add_Orders)
t4=Button(text='Add',bg='green')
t4.bind('<Button-1>',Case_Add_Clients)
t5=Button(text='Add',bg='green')
t5.bind('<Button-1>',Case_Add_Options)
t6=Button(text='TEST',bg='green')
t6.bind('<Button-1>',Case_Add_About_us)
t8=Button(text='TEST',bg='green')
t8.bind('<Button-1>',Case_Test_CaseShopping)
t1.grid(row=1,column=1)
t2.grid(row=2,column=1)
t3.grid(row=3,column=1)
t4.grid(row=4,column=1)
t5.grid(row=5,column=1)
t6.grid(row=6,column=1)
t8.grid(row=8,column=1)
b0=Button(text='ปิดโปรแกรม')
b0.bind('<Button-1>',Exit)
b0.grid(row=10,)
gui.mainloop()
[b]สอบถามการ ผูกฟังก์ชัน ข้ามไพล์ ด้วยโมดูล Tkinter [/b]
ผมได้ทำการสร้างไฟล์ python เพื่อทำหน้า window from GUI แล้วต้องการสร้างปุ่มให้มีความสามารถ
กดปุ่มแล้วฟังก์ชันที่อยู่ อีกไฟล์หนึ่ง ทำงาน หรือ(ปุ่มผูกฟังก์ชัน)
ผมได้ทำการ import ไฟล์ให้สามารถเรียกใช้ ฟังก์ชัน ของ อีกไฟล์หนึ่งได้แล้ว แต่ไม่สามารถ สั่งให้อีกไฟล์ Run ได้
[b][u]มันแจ้งErrorว่า[/u][/b]
[b][color=#FF0000]AttributeError: 'Event' object has no attribute 'categories_check_Add'[/color][/b]
[img]http://snap.mindphp.com/index.php?view=2019Feb06_5c5ac023b34fa[/img]
[b][color=#FF0000]บรรทัดที่Error[/color][/b]
[img]http://snap.mindphp.com/index.php?view=2019Feb06_5c5ac1472d4cf[/img]
[b][color=#FF0000]ข้อความที่Error[/color][/b]
[quote]
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\ter\AppData\Local\Programs\Python\Python36\lib\tkinter\__init__.py", line 1705, in __call__
return self.func(*args)
File "D:/Python selenium_mt27/python_test/Mt27/selenium_moozii/GUI_MooZii Cart_01.py", line 20, in Case_Add_Categories
test=self.categories_check_Add()
AttributeError: 'Event' object has no attribute 'categories_check_Add'
[/quote]
[b][u]โค้ดทั้งหมด ของตัว หน้า window from[/u][/b]
[code]from tkinter import *
from tkinter import messagebox
from TestBotmoozii import MooZiiCart_check , joomla
import sys
class GUI_MooZii(MooZiiCart_check):
def Exit(self):
status=messagebox.askyesno(title='คำยืนยัน',message='ปิดหรือไม่')#ปิดโปรแกรม
if status>0:
print('กด off')
sys.exit()
def Case_Add_Categories(self):
print('Case Add Categories')
test=self.categories_check_Add()
def Case_Add_Products(self):
print('Case Add Products')
def Case_Add_Orders(self):
print('Case Add Orders')
def Case_Add_Clients(self):
print('Case Add Clients')
def Case_Add_Options(self):
print('Options')
def Case_Add_About_us(self):
print('Case Add About us')
def Case_Test_CaseShopping(self):
print('Case Shopping')
# สร่้างหน้าจอ
gui=Tk()
gui.geometry("450x450") #ขนาดframe กว้าง*สูง
gui.title("MooZii Cart") #ชื่อframe
Mlable=Label(text='BACK-END',fg='green',bg='#CCFFFF')
Mlable.grid(row=0)
Mlable=Label(text='FRONT-END',fg='green',bg='#CCFFFF')
Mlable.grid(row=7)
# รายการที่เทส
l1=Label(text='Categories',bg='#80FF80')
l2=Label(text='Product',bg='#80FF80')
l3=Label(text='Orders',bg='#80FF80')
l4=Label(text='Clients',bg='#80FF80')
l5=Label(text='Options',bg='#80FF80')
l6=Label(text='About us',bg='#80FF80')
l8=Label(text='Case Shopping',bg='#80FF80')
l1.grid(row=1)
l2.grid(row=2)
l3.grid(row=3)
l4.grid(row=4)
l5.grid(row=5)
l6.grid(row=6)
l8.grid(row=8)
t1=Button(text='Add',bg='green')
t1.bind('<Button-1>',Case_Add_Categories)
t2=Button(text='Add',bg='green')
t2.bind('<Button-1>',Case_Add_Products)
t3=Button(text='Add',bg='green')
t3.bind('<Button-1>',Case_Add_Orders)
t4=Button(text='Add',bg='green')
t4.bind('<Button-1>',Case_Add_Clients)
t5=Button(text='Add',bg='green')
t5.bind('<Button-1>',Case_Add_Options)
t6=Button(text='TEST',bg='green')
t6.bind('<Button-1>',Case_Add_About_us)
t8=Button(text='TEST',bg='green')
t8.bind('<Button-1>',Case_Test_CaseShopping)
t1.grid(row=1,column=1)
t2.grid(row=2,column=1)
t3.grid(row=3,column=1)
t4.grid(row=4,column=1)
t5.grid(row=5,column=1)
t6.grid(row=6,column=1)
t8.grid(row=8,column=1)
b0=Button(text='ปิดโปรแกรม')
b0.bind('<Button-1>',Exit)
b0.grid(row=10,)
gui.mainloop()
[/code]