WM_DELETE_WINDOW ใน wxPython

  • warning: realpath() [function.realpath]: SAFE MODE Restriction in effect. The script whose uid is 1005 is not allowed to access /tmp owned by uid 0 in /var/www/sites/sugree/codenone.com/subdomains/www/html/includes/file.inc on line 190.
  • warning: realpath() [function.realpath]: SAFE MODE Restriction in effect. The script whose uid is 1005 is not allowed to access /tmp owned by uid 0 in /var/www/sites/sugree/codenone.com/subdomains/www/html/includes/file.inc on line 190.

คือผมจะตรวจสอบ user ตอนที่คลิ๊กปิดที่window นะครับ
หากใช้ใน Tkinter ก็ใช้แบบนี้

root.protocol("WM_DELETE_WINDOW", YouQuit())

แต่ใน wxPython ใช้อย่างไรหรือครับ

sugree's picture

self เป็น wxFrame

self.bind(wx.EVT_CLOSE, self.OnClose)

khao_lek's picture

ขอบคุณ sugree มากครับ แต่ขอสอบถามเพิ่มนิดหนึ่งครับ
ว่า เอาไปใส่ในตรงไหนดีหรือคับ
คือผมสร้างเป็น class แล้วผมไปใส่ไว้ใน init
กลับกลายเป็นว่ามันทำงานตั้งแต่เริ่มโปรแกรมเลยคับ
มันไม่ได้รอจนกว่าเราจะปิดหรือคับ

sugree's picture

__init__ ของ wxFrame เหรอครับ อันนี้แค่ bind นี่

khao_lek's picture

ผมสร้าง class แล้ว extends มาจาก wxFrame นะครับ แล้ว
เอา code ของคุณ sugree มาใส่ไว้ใน __init__ ของ class
ที่ผมสร้างนะครับ

sugree's picture

เอาแบบเต็มๆ ดีกว่า ไอ้ที่ผมบอกไปข้างบนมัน wx เก่าไปหน่อย

#!/usr/bin/env python
 
import wx
import sys
 
class MyFrame(wx.Frame):
    def __init__(self, parent, ID, title):
        wx.Frame.__init__(self, parent, ID, title)
 
        wx.EVT_CLOSE(self, self.OnClose)
 
    def OnClose(self, event):
        print event
        sys.exit()
 
class MyApp(wx.App):
    def OnInit(self):
        frame = MyFrame(None, -1, "test evt_close")
        frame.Show(True)
        self.SetTopWindow(frame)
        return True
 
if __name__ == '__main__':
    app = MyApp()
    app.MainLoop()
khao_lek's picture

ขอบคุณครับ เดี๋ยวขอกลับไปลองก่อนครับ

ย้าย Codenone

ประกาศย้าย Codenone ไปใช้ Forum ของ Blognone แทนครับ ตามไปตั้งกระทู้ต่อได้ที่ Codenone Forum (รายละเอียดอ่านจากกระทู้ ย้าย Codenone ไปรวมกับ Blognone)

กระทู้เก่าๆ จะย้ายตามไปในภายหลัง ตอนนี้ปิดการโพสต์กระทู้ไว้ เหลือไว้เฉพาะอ้างอิงเท่านั้น