线程内的调用消息对话框(python + gtk3)

时间:2017-06-28 22:41:48

标签: python user-interface gtk3 python-multithreading

我试着在一个线程中调用一个消息对话框(使用python3和gtk3),在下一个例子中,当我按下按钮时标签开始每1秒更改一次文本,这部分工作正常,问题出现在我取消注释self.Mensage_Falla(“final”),应用程序为自己关闭,这里是代码,看看是否有人可以告诉我光:

import threading
import time
import serial
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, Gdk, Pango, GLib, GdkPixbuf, GObject

class GridWindow(Gtk.Window):
    def __init__(self):
        Gtk.Window.__init__(self, title="TEST")
        self.set_border_width(15)
        self.grid = Gtk.Grid()
        self.grid.set_column_spacing(25)
        self.grid.set_row_spacing(25)
        self.add(self.grid)

        self.label1 = Gtk.Label("NUMERO DE SERIE")
        self.txtSerialNumber = Gtk.Entry()

        btnStartTest=Gtk.Button("Iniciar Prueba")
        btnStartTest.connect("clicked",self.StartTest_Tread)

        self.grid.add(self.label1)
        self.grid.attach(btnStartTest, 0, 1, 1, 1)

    def StartTest_Tread(self,widget):
        self.thread = threading.Thread(target=self.StartTest)
        self.thread.daemon = True
        self.thread.start()

    def StartTest(self):
        self.label1.set_text("xxxx")
        time.sleep(1)
        self.label1.set_text("yyyy")
        time.sleep(1)
        self.label1.set_text("zzzz")
        time.sleep(1)
        self.label1.set_text("aaaa")
        self.Mensage_Falla("final")


    def Mensage_Falla(self, UUT_Failure):
        dialog = Gtk.MessageDialog(self, 0, Gtk.MessageType.INFO,
            Gtk.ButtonsType.OK, "UUT")
        dialog.format_secondary_text(
            "LA UUT A FALLADO LA PRUEBA " + UUT_Failure)
        dialog.run()
        dialog.destroy() 
        print("fALLA")



try:
    GObject.threads_init()
    win = GridWindow()
    win.set_position(Gtk.WindowPosition.CENTER)
    win.set_default_size(100,100)
    win.set_type_hint(Gdk.WindowTypeHint.MENU)
    win.connect("delete-event", Gtk.main_quit)
    win.show_all()
    Gtk.main()
except ValueError as Argument:
    print ("The argument does not contain numbers\n", Argument)
    print("error " + str(Exception.args))
    time.sleep(30)

0 个答案:

没有答案