Tkinter testmaker – part II

Second part of this app made with tkinter to create a different test for every student, taking random data and having back the solution to easily grade them.

This is the first part, click here to watch it.

Tkinter app to make a different test for every student – part 1

The output

The code

import tkinter as tk
# import os
# from random import choice, randrange


class Window:
    def __init__(self):
        self.root = tk.Tk()
        self.mem = {}

    def label(self, text, r, c):
        "Creates a label with a text and row and column as arguments"
        self.label = tk.Label(
            self.root,
            text=text)
        self.label.grid(row=r, column=c)
        return self.label

    def entry(self, r, c):
        "Creates an input entry for the user"
        self.v = tk.StringVar()
        self.e = tk.Entry(
            self.root,
            textvariable=self.v)
        self.e.grid(row=r, column=c)
        return self.e

    def textarea(self, r, c):
        "Creates an input entry for the user"
        # self.v = tk.StringVar()
        self.t = tk.Text(
            self.root)
        self.t.grid(row=r, column=c, columnspan=2)
        return self.t

    def memorize(self, key, data):
        self.mem[key] = data
        print(self.mem)


    def number_of_students(self):
        "Creates the input of number of students"
        label = w.label("Number of students", 0, 0)
        entry = w.entry(0, 1)
        entry.focus()
        entry.bind("<Return>", lambda x: w.memorize(label["text"], self.v.get()))

    def template(self):
        "Creates the template for the test"
        ta = w.textarea(1, 0)
        ta.bind("<Return>", lambda x: w.memorize("template", ta.get("0.0", tk.END)))


def main():
    "Show the widgets"
    w.number_of_students()
    w.template()


# ============ Launch the app
w = Window()
main()
w.root.mainloop()

 

The video of the live coding


Subscribe to the newsletter for updates
Tkinter templates
Avatar My youtube channel

Twitter: @pythonprogrammi - python_pygame

Videos

Speech recognition game

Pygame's Platform Game

Other Pygame's posts

Published by pythonprogramming

Started with basic on the spectrum, loved javascript in the 90ies and python in the 2000, now I am back with python, still making some javascript stuff when needed.