0

Ive tried both multiprocessing and threading in order to achieve my goal however I am encountering one of two errors regardless. When I click a Tkinter button I call a function that I want to simultaneously execute both a class that involves a new window as well as a timer. However, it will always execute the timer and then waits for its while loop to finish before executing the class. So As A result I split it into a target and args however now I get:

I get the TypeError int is not Iterable

def quiz():
        th1 = threading.Thread(target=QuizApp)
        th2 = threading.Thread(target=timecount, args=(int(countmin.get())))
        th2.start()
        th1.start()

This is the function that is called by the button (countmin.get() is retrieving the textvariable of a spinbox)

#Importing Python Packages
import sys
import time
import threading
from tkinter import *
from tkinter import ttk
import tkinter as tk


#Loading Of Images

LARGE_FONT= ("Verdana", 12)


class QuizApp(tk.Tk):

    def __init__(self, *args, **kwargs):

        tk.Tk.__init__(self, *args, **kwargs)

        tk.Tk.iconbitmap(self, default='icon.ico')
        tk.Tk.wm_title(self, "Bugz - HSC SDD Quiz")

        container = ttk.Frame(self)
        container.pack(side="top", fill="both", expand = True)
        container.grid_rowconfigure(0, weight=1)
        container.grid_columnconfigure(0, weight=1)

        self.frames = {}

        for F in (StartPage, PageFinish, Page1, Page2, Page3, Page4, Page5, Page6, Page7, Page8, Page9, Page10):

            frame = F(container, self)

            self.frames[F] = frame

            frame.grid(row=0, column=0, sticky="nsew")

        self.show_frame(StartPage)

    def show_frame(self, cont):

        frame = self.frames[cont]
        frame.tkraise()


class StartPage(tk.Frame):

    def __init__(self, parent, controller):
        ttk.Frame.__init__(self,parent)
        label = ttk.Label(self, text="Welcome To The Quiz!", font=LARGE_FONT)
        label.pack(pady=10,padx=10)

        button1 = ttk.Button(self, text="Next",
                            command=lambda: controller.show_frame(Page1))
        button1.pack()

This is A Part of the Class QuizApp()

#Used to Determine the customisable counter as well as general time management
#Should be noted 59 seconds is used because function begins counting every second at 00 instead of 01
def timecount(minutes):
    start = time.time()
    time.clock()    
    sec_elapsed = 0
    min_elapsed = 0
    while min_elapsed < minutes:
        sec_elapsed = time.time() - start
        print("minutes count:",min_elapsed,"loop cycle time: %f, seconds count: %02d" % (time.clock() , sec_elapsed)) 
        time.sleep(1)
        if sec_elapsed > 59:
            min_elapsed += 1
            start = time.time()
    print("Times Up!")

This is the counter that seems to always activate first in the threads or multiproccessing. I have the while loop as when it finishes I am going to use it to pre-emptively finish the quiz.

I have tried Various methods of fixing this although to no avail. If I try substituting the threads with:

I feel like this is a stupid mistake although I cannot spot it.

CodeBugZ
  • 1
  • 1

0 Answers0