kas*_*ten 2 python unit-testing tkinter
我正在尝试对我的 tkitner GUI 进行单元测试。
因此我尝试从单独的线程生成点击事件。下面是测试 Tkinter.Button 的示例:
import unittest, threading
from Tkinter import *
class clickThread(threading.Thread):
def __init__(self, root):
threading.Thread.__init__(self)
self.root = root
def run(self):
button = filter(lambda a: isinstance(a, Button), self.root.children.values())[0]
print button
button.focus()
button.event_generate("<Button-1>")
button.event_generate("<ButtonRelease-1>")
print "clicked"
class Test(unittest.TestCase):
def testName(self):
root = Tk()
button = Button(root, command=self.returnEvent)
button.pack()
thread = clickThread(root)
thread.start()
root.mainloop()
def returnEvent(self):
print "!"
Run Code Online (Sandbox Code Playgroud)
我生成的单击事件未调用 Test.returnEvent 方法。但如果我真正点击一下,它就会按预期工作。
| 归档时间: |
|
| 查看次数: |
5194 次 |
| 最近记录: |