12

I found a great Website that discusses functional testing a Python GUI application using IronPython: http://www.voidspace.org.uk/python/articles/testing/ but I want to use Tkinter and am having a hard time making the transition between the libraries.

Michael shows this example for IronPython:

class FunctionalTest(TestCase):

    def setUp(self):
        self.mainForm = None
        self._thread = Thread(ThreadStart(self.startMultiDoc))
        self._thread.SetApartmentState(ApartmentState.STA)
        self._thread.Start()
        while self.mainForm is None:
            Thread.CurrentThread.Join(100)

    def invokeOnGUIThread(self, function):
        return self.mainForm.Invoke(CallTarget0(function))

...and I'm having a hard time translating that into how I would hook into a Tkinter based application that would have the base setup:

from tkinter import *
from tkinter import ttk

root = Tk()
ttk.Button(root, text="Hello World").grid()
root.mainloop()

...I'm thinking you would want to run a method on the main root object in the second thread as well but I'm not seeing an equivalent method to the mainForm.Invoke(). Maybe I'm thinking about it wrong. Maybe functional testing GUI applications in this manner is not so common?

Examples would be awesome!

Wes Grant
  • 621
  • 5
  • 11

1 Answers1

-7

So to be clear you want a working tkinter program? If you do here is one if not I'm sorry to waste you'r time because I miss understood your question. Here is something I've been working on for a while. It isn't done yet. It is a log-on screen That will eventually validate the username and password.

import tkinter
def Mainscreen():
    def Validate():
         with open('Users.txt', 'w') as fout:
         fout.write("test")
    def Quit():
         window.destroy()
    def Sighnup():
        window2 = tkinter. Tk()
        def Quit2 ():
            window2.destroy()
        def Sighnup():
            with open('Users.txt', 'w') as fout:
                fout.write(ent.get())
                fout.write(ent2.get())
                fout.write(ent3.get())
                fout.write(ent4.get())
                fout.write(ent5.get())
            window2.destroy()
        window2.geometry("195x135")
        window2.title("Sighnup")
        window2.wm_iconbitmap('favicon.ico')
        lbl= tkinter.Label(window2, text="First Name:")
        lbl2= tkinter.Label(window2, text="Last Name:")
        lbl3= tkinter.Label(window2, text="Email:")
        lbl4=  tkinter.Label(window2, text="Username:")
        lbl5= tkinter.Label(window2, text="Password:")
        ent= tkinter.Entry(window2)
        ent2= tkinter.Entry(window2)
        ent3= tkinter.Entry(window2)
        ent4= tkinter.Entry(window2)
        ent5= tkinter.Entry(window2)
        btn= tkinter.Button(window2, text="Submit", command=Sighnup)  #command=Loginpostsighnup
        btn2= tkinter.Button(window2, text="Quit", command=Quit2)
        lbl.grid(row=0, column=0)
        ent.grid(row=0, column=1)
        lbl2.grid(row=1, column=0)
        ent2.grid(row=1, column=1)
        lbl3.grid(row=2, column=0)
        ent3.grid(row=2, column=1)
        lbl4.grid(row=3, column=0)
        ent4.grid(row=3, column=1)
        lbl5.grid(row=4, column=0)
        ent5.grid(row=4, column=1)
        btn2.grid(row=5, column=1)
        btn.grid(row=5, column=0)
        window2.mainloop()
    window = tkinter. Tk()
    window.geometry("195x135")
    window.title("Login")
    window.wm_iconbitmap('favicon.ico') 
    lbl6= tkinter.Label(window, text="Login:")
    lbl7= tkinter.Label(window, text="Username:")
    lbl8= tkinter.Label(window, text="Password:")
    ent6= tkinter.Entry(window)
    ent7= tkinter.Entry(window)
    btn3= tkinter.Button(window, text="Login")
    btn4= tkinter.Button(window, text="Sighn up", command=Sighnup)
    btn5= tkinter.Button(window, text="Quit", command=Quit)
    lbl6.grid(row=0, column=0)
    lbl7.grid(row=1, column=0)
    lbl8.grid(row=2, column=0)
    ent6.grid(row=1, column=1)
    ent7.grid(row=2, column=1)
    btn3.grid(row=3, column=1)
    btn4.grid(row=3, column=0)
    btn5.grid(row=4, column=0)
#main
(Mainscreen())
Jordanian
  • 1
  • 10