Bad programmer
Bad programmer

Reputation: 46

Robot framework opening up multiple windows of Tkinter

I'm currently calling up a class from my robot framework script and it opens up two windows of Tkinter. I've tried running my python object via PyCharm and through the cmd and i only get one Tkinter window through that. However when i call my object through RobotFramework it opens up a blank Tk window and the expected Tk window. Any ideas?

My Hello.py is:

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()

My tk_hello file contents are:

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()

My Robot Framework script is:

*** 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}

Upvotes: 0

Views: 625

Answers (1)

Bryan Oakley
Bryan Oakley

Reputation: 385970

When you import Hello.py, robot detects a class named hello so it automatically instantiates it. It creates a root window in the __init__ function, so that's your first window.

When you import tk_hello.py, robot detects a class named tk_hello, so it automatically instantiates it. It creates a root window in the __init__ function, that's your second window.

Upvotes: 2

Related Questions