【问题标题】:Robot framework opening up multiple windows of Tkinter机器人框架打开 Tkinter 的多个窗口
【发布时间】:2019-02-21 07:24:11
【问题描述】:

我目前正在从我的机器人框架脚本中调用一个类,它会打开两个 Tkinter 窗口。我尝试通过 PyCharm 和 cmd 运行我的 python 对象,但我只能通过它获得一个 Tkinter 窗口。但是,当我通过 RobotFramework 调用我的对象时,它会打开一个空白的 Tk 窗口和预期的 Tk 窗口。有什么想法吗?

我的 Hello.py 是:

from Tkinter import *


class hello(object):
    def __init__(self, question="Not today"):
        self.question = question
        self.master = Tk()
        self.lbl = Label(self.master, text=self.question)
        self.lbl.pack()
        self.btn = Button(self.master, text="Yes", command=self.yes_command)
        self.btn.pack()
        self.master.mainloop()

    def yes_command(self):
        print("User pressed Yes")
        self.master.quit()
        self.master.destroy()

我的 tk_hello 文件内容是:

from Tkinter import *


class tk_hello(object):
    def __init__(self, question):
        self.question = question
        self.master = Tk()
        self.lbl = Label(self.master, text=self.question)
        self.lbl.pack()
        self.btn = Button(self.master, text="Yes", command=self.yes_command)
        self.btn.pack()
        self.master.mainloop()

    def yes_command(self):
        print("User pressed Yes")
        self.master.quit()
        self.master.destroy()

我的机器人框架脚本是:

*** Settings ***
Library           hello.py

*** Variables ***

*** Test Cases ***
Example_1
    Import Library    ${CURDIR}\\..\\work_project\\tk_hello.py    "Worked"    WITH NAME    Try_This
    Log To Console    \r ${CURDIR}

【问题讨论】:

  • 我无法复制您报告的问题,也没有看到任何可能导致它的问题。您确定这个确切的代码会重现问题吗?
  • Appologies @BryanOakley,我现在已经完整添加了代码
  • Robot Framework 和 Tkiniter 的交集——没有比 Bryan Oakley 更好的匹配了 :)

标签: python tkinter robotframework


【解决方案1】:

当您导入 Hello.py 时,robot 会检测到一个名为 hello 的类,因此它会自动实例化它。它在__init__ 函数中创建一个根窗口,所以这是您的第一个窗口。

当你导入 tk_hello.py 时,robot 会检测到一个名为 tk_hello 的类,因此它会自动实例化它。它在__init__ 函数中创建一个根窗口,这是您的第二个窗口。

【讨论】:

    猜你喜欢
    • 2019-08-07
    • 2017-08-12
    • 2017-05-17
    • 1970-01-01
    • 1970-01-01
    • 2013-09-18
    • 2018-05-11
    • 2018-11-17
    • 1970-01-01
    相关资源
    最近更新 更多