Does anyone know a good example of functional testing a Python Tkinter application?

I found a great website that discusses functional testing of a Python GUI application using IronPython: http://www.voidspace.org.uk/python/articles/testing/ , but I want to use Tkinter and have it that makes it difficult to switch between 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 it’s hard for me to translate this into how I connect to the Tkinter application, which will have a basic configuration:

from tkinter import *
from tkinter import ttk

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

... I think that you will want to run the method on the main root object in the second thread, but I do not see the equivalent method for mainForm.Invoke (). Maybe I'm thinking about it wrong. Perhaps functional testing of GUI applications this way is not so common?

!

+4
1

, , tkinter? , , , , . -, . . , .

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

All Articles