Next Tray 19.1

This commit is contained in:
H4nSolo committed 2024-07-19 08:26:59 +02:00
1 parent bbe2cfb571
commit b998fbdbf5
9 files changed
+261 -49

No files matched your search

+93
View File
@@ -0,0 +1,93 @@
import tkinter as tk
from tkinter import messagebox
import sqlite3
import csv
import random
class QuizApp:
def __init__(self, root):
self.root = root
self.root.title("Karteikarten Quiz")
self.questions = []
self.current_question = 0
self.score = 0
self.load_questions()
self.question_label = tk.Label(root, text="", wraplength=300)
self.question_label.pack(pady=20)
self.options = tk.StringVar()
self.option_buttons = []
for _ in range(4):
rb = tk.Radiobutton(root, text="", variable=self.options, value="")
rb.pack(anchor=tk.W)
self.option_buttons.append(rb)
self.submit_button = tk.Button(root, text="Antworten", command=self.check_answer)
self.submit_button.pack(pady=10)
self.score_label = tk.Label(root, text="Punkte: 0")
self.score_label.pack(pady=20)
self.show_question()
def load_questions(self):
# Wählen Sie zwischen CSV oder SQLite
use_csv = True
if use_csv:
self.load_questions_from_csv("questions.csv")
else:
self.load_questions_from_sqlite("quiz.db")
def load_questions_from_csv(self, filename):
with open(filename, newline='', encoding='utf-8') as csvfile:
reader = csv.reader(csvfile)
for row in reader:
if row:
question, correct_answer, *options = row
self.questions.append((question, correct_answer, options))
def load_questions_from_sqlite(self, dbname):
conn = sqlite3.connect(dbname)
cursor = conn.cursor()
cursor.execute("SELECT question, correct_answer, option1, option2, option3, option4 FROM questions")
rows = cursor.fetchall()
for row in rows:
question = row[0]
correct_answer = row[1]
options = row[2:]
self.questions.append((question, correct_answer, options))
conn.close()
def show_question(self):
if self.current_question < len(self.questions):
question, correct_answer, options = self.questions[self.current_question]
self.question_label.config(text=question)
random.shuffle(options)
for rb, option in zip(self.option_buttons, options):
rb.config(text=option, value=option)
self.options.set(None)
else:
self.end_quiz()
def check_answer(self):
if self.current_question < len(self.questions):
_, correct_answer, _ = self.questions[self.current_question]
user_answer = self.options.get()
if user_answer == correct_answer:
self.score += 1
self.current_question += 1
self.score_label.config(text=f"Punkte: {self.score}")
self.show_question()
def end_quiz(self):
messagebox.showinfo("Quiz Ende", f"Du hast {self.score} von {len(self.questions)} Punkten erreicht!")
self.root.quit()
if __name__ == "__main__":
root = tk.Tk()
app = QuizApp(root)
root.mainloop()
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

+19 -46
View File
@@ -8,63 +8,36 @@
##
#############################################################################################
## Important Modules
import tkinter as tk
from tkinter import Menu
from tkinter.filedialog import askopenfilename
from tkinter import Toplevel
def open_database():
# tk().withdraw()
filename = askopenfilename()
print(filename)
# print("Open Database selected")
def reload():
print("Reload selected")
## Own Modules
import scripts.mainframe
def quit_app():
root.quit()
def start_questions():
print("Start selected")
def open_new_window():
new_window = Toplevel(root)
new_window.title("Neues Fenster")
new_window.geometry("300x200")
label = tk.Label(new_window, text="Dies ist ein neues Fenster")
label.pack(pady=20)
button = tk.Button(new_window, text="Schließen", command=lambda: new_window_destroy(new_window))
button.pack(pady=20)
def stop_questions():
print("Stop selected")
def new_window_destroy(data):
print(f"Destroy New Window {data}")
data.destroy()
def new_questions():
print("New Questions selected")
def edit_questions():
print("Edit Questions selected")
def about():
print("About selected")
main_label = tk.Label(root, text="Hauptfenster Inhalt")
main_label.pack(pady=20)
root = tk.Tk()
root.title("Dropdown Menüleiste Beispiel")
open_button = tk.Button(root, text="Neues Fenster öffnen", command=open_new_window)
open_button.pack(pady=20)
menubar = Menu(root)
# File menu
filemenu = Menu(menubar, tearoff=0)
filemenu.add_command(label="Open Database", command=open_database)
filemenu.add_command(label="Reload", command=reload)
filemenu.add_separator()
filemenu.add_command(label="Quit", command=quit_app)
menubar.add_cascade(label="File", menu=filemenu)
# Questions menu
questionsmenu = Menu(menubar, tearoff=0)
questionsmenu.add_command(label="Start", command=start_questions)
questionsmenu.add_command(label="Stop", command=stop_questions)
questionsmenu.add_separator()
questionsmenu.add_command(label="New Questions", command=new_questions)
questionsmenu.add_command(label="Edit Questions", command=edit_questions)
menubar.add_cascade(label="Questions", menu=questionsmenu)
# About menu
aboutmenu = Menu(menubar, tearoff=0)
aboutmenu.add_command(label="About", command=about)
menubar.add_cascade(label="About", menu=aboutmenu)
root.config(menu=menubar)
root.mainloop()
+4
View File
@@ -0,0 +1,4 @@
question,option1,option1,option2,option3,option4
Was ist die Hauptstadt von Deutschland?,Berlin,Berlin,München,Hamburg,Köln
Wie viele Kontinente gibt es?,7,5,6,7,8
Wer hat die Relativitätstheorie entwickelt?,Albert Einstein,Isaac Newton,Albert Einstein,Galileo Galilei,Nikola Tesla
1 question option1 option1 option2 option3 option4
2 Was ist die Hauptstadt von Deutschland? Berlin Berlin München Hamburg Köln
3 Wie viele Kontinente gibt es? 7 5 6 7 8
4 Wer hat die Relativitätstheorie entwickelt? Albert Einstein Isaac Newton Albert Einstein Galileo Galilei Nikola Tesla
BIN
View File
Binary file not shown.
+61
View File
@@ -0,0 +1,61 @@
import tkinter as tk
from tkinter import Menu
from tkinter.filedialog import askopenfilename
def open_database():
# tk().withdraw()
filename = askopenfilename()
print(filename)
# print("Open Database selected")
def reload():
print("Reload selected")
def quit_app():
root.quit()
def start_questions():
print("Start selected")
def stop_questions():
print("Stop selected")
def new_questions():
print("New Questions selected")
def edit_questions():
print("Edit Questions selected")
def about():
print("About selected")
root = tk.Tk()
root.title("Python Karteikarten Quiz")
root.geometry('640x480+300+300')
root.resizable(False, False)
menubar = Menu(root)
# File menu
filemenu = Menu(menubar, tearoff=0)
filemenu.add_command(label="Open Database", command=open_database)
filemenu.add_command(label="Reload", command=reload)
filemenu.add_separator()
filemenu.add_command(label="Quit", command=quit_app)
menubar.add_cascade(label="File", menu=filemenu)
# Questions menu
questionsmenu = Menu(menubar, tearoff=0)
questionsmenu.add_command(label="Start", command=start_questions)
questionsmenu.add_command(label="Stop", command=stop_questions)
questionsmenu.add_separator()
questionsmenu.add_command(label="New Questions", command=new_questions)
questionsmenu.add_command(label="Edit Questions", command=edit_questions)
menubar.add_cascade(label="Questions", menu=questionsmenu)
# About menu
aboutmenu = Menu(menubar, tearoff=0)
aboutmenu.add_command(label="About", command=about)
menubar.add_cascade(label="About", menu=aboutmenu)
root.config(menu=menubar)
-3
View File
@@ -1,3 +0,0 @@
class mainframe():
def __init__(self):
pass
+69
View File
@@ -0,0 +1,69 @@
CREATE TABLE questions (
id INTEGER PRIMARY KEY AUTOINCREMENT,
question TEXT NOT NULL,
correct_answer TEXT NOT NULL,
option1 TEXT NOT NULL,
option2 TEXT NOT NULL,
option3 TEXT NOT NULL,
option4 TEXT NOT NULL
);
INSERT INTO questions (question, correct_answer, option1, option2, option3, option4) VALUES
('Was ist die Hauptstadt von Deutschland?', 'Berlin', 'Berlin', 'München', 'Hamburg', 'Köln'),
('Wie viele Kontinente gibt es?', '7', '5', '6', '7', '8'),
('Wer hat die Relativitätstheorie entwickelt?', 'Albert Einstein', 'Isaac Newton', 'Albert Einstein', 'Galileo Galilei', 'Nikola Tesla');
INSERT INTO py_questions VALUES (20, 1, 1, 'Was ist der Zweck der Funktion `print()` in Python?', 'Gibt Werte in die Konsole aus', 'Kommentiert den Code', 'Fügt zwei Zahlen hinzu', 'Liests Werte von der Konsole ein', 1, 'easy');
INSERT INTO py_questions VALUES (21, 1, 1, 'Wie kommentiert man eine einzelne Zeile in Python?', '# Kommentar', '/* Kommentar */', '<!-- Kommentar -->', '// Kommentar', 1, 'easy');
INSERT INTO py_questions VALUES (22, 1, 1, 'Welche Dateiendung wird für Python-Dateien verwendet?', '.python', '.py', '.pt', '.pyt', 2, 'easy');
INSERT INTO py_questions VALUES (23, 2, 1, 'Wie erstellt man eine Liste in Python?', '[]', '()', '<>', '{}', 1, 'easy');
INSERT INTO py_questions VALUES (24, 2, 1, 'Wie greift man auf das zweite Element einer Liste zu?', 'liste[0]', 'liste[1]', 'liste[2]', 'liste[3]', 2, 'easy');
INSERT INTO py_questions VALUES (25, 1, 2, 'Welches Schlüsselwort verwendet man, um eine Funktion zu definieren?', 'define', 'function', 'def', 'fun', 3, 'easy');
INSERT INTO py_questions VALUES (26, 1, 2, 'Welcher Datentyp wird für Zeichenketten in Python verwendet?', 'char', 'text', 'string', 'str', 4, 'easy');
INSERT INTO py_questions VALUES (27, 2, 2, 'Wie entfernt man das letzte Element aus einer Liste?', 'remove()', 'pop()', 'discard()', 'delete()', 2, 'easy');
INSERT INTO py_questions VALUES (28, 2, 2, 'Welche Methode wird verwendet, um ein Element an eine Liste anzuhängen?', 'push()', 'add()', 'append()', 'insert()', 3, 'easy');
INSERT INTO py_questions VALUES (29, 3, 1, 'Was ist ein Konstruktor in einer Klasse?', 'Eine Methode, die eine Klasse erstellt', 'Eine Methode, die ein Objekt kopiert', 'Eine Methode, die beim Erstellen eines Objekts aufgerufen wird', 'Eine Methode, die ein Objekt zerstört', 3, 'middle');
INSERT INTO py_questions VALUES (30, 3, 1, 'Welches Schlüsselwort wird verwendet, um eine Klasse zu definieren?', 'define', 'class', 'def', 'klass', 2, 'easy');
INSERT INTO py_questions VALUES (31, 4, 1, 'Welche Bibliothek wird zum Plotten von Graphen in Python verwendet?', 'numpy', 'pandas', 'seaborn', 'matplotlib', 4, 'easy');
INSERT INTO py_questions VALUES (32, 4, 1, 'Wie importiert man eine Bibliothek in Python?', 'include library', 'require library', 'import library', 'use library', 3, 'easy');
INSERT INTO py_questions VALUES (33, 5, 1, 'Wie fängt man eine Ausnahme in Python ab?', 'try-catch', 'try-except', 'catch-throw', 'except-try', 2, 'easy');
INSERT INTO py_questions VALUES (34, 5, 1, 'Welcher Fehler tritt auf, wenn man auf eine nicht existierende Liste zugreift?', 'KeyError', 'ValueError', 'TypeError', 'IndexError', 4, 'easy');
INSERT INTO py_questions VALUES (35, 1, 3, 'Welches Schlüsselwort wird verwendet, um eine Schleife zu beenden?', 'end', 'stop', 'exit', 'break', 4, 'easy');
INSERT INTO py_questions VALUES (36, 1, 3, 'Wie konvertiert man eine Zeichenkette in eine Ganzzahl?', 'int()', 'str()', 'float()', 'bool()', 1, 'easy');
INSERT INTO py_questions VALUES (37, 2, 3, 'Wie zählt man die Anzahl der Elemente in einer Liste?', 'length()', 'len()', 'size()', 'count()', 2, 'easy');
INSERT INTO py_questions VALUES (38, 2, 3, 'Wie fügt man ein Element an einer bestimmten Position in einer Liste ein?', 'append()', 'add()', 'put()', 'insert()', 4, 'easy');
INSERT INTO py_questions VALUES (39, 3, 2, 'Wie nennt man die Methode, die eine Zeichenkette in Kleinbuchstaben umwandelt?', 'downcase()', 'small()', 'lower()', 'tolower()', 3, 'easy');
INSERT INTO py_questions VALUES (40, 3, 2, 'Wie nennt man die Methode, die eine Zeichenkette in Großbuchstaben umwandelt?', 'upcase()', 'big()', 'upper()', 'toupper()', 3, 'easy');
INSERT INTO py_questions VALUES (41, 4, 2, 'Welche Bibliothek wird zum Bearbeiten von Arrays in Python verwendet?', 'pandas', 'numpy', 'scipy', 'sklearn', 2, 'easy');
INSERT INTO py_questions VALUES (42, 4, 2, 'Welche Methode wird verwendet, um Daten aus einem DataFrame zu entfernen?', 'remove()', 'drop()', 'delete()', 'discard()', 2, 'easy');
INSERT INTO py_questions VALUES (43, 5, 2, 'Welche Ausnahme tritt auf, wenn man eine nicht existierende Datei öffnet?', 'IOError', 'FileNotFoundError', 'OSError', 'NameError', 2, 'middle');
INSERT INTO py_questions VALUES (44, 5, 2, 'Welches Schlüsselwort wird verwendet, um eine Ausnahme auszulösen?', 'except', 'raise', 'throw', 'catch', 2, 'middle');
INSERT INTO py_questions VALUES (45, 1, 4, 'Wie schreibt man eine mehrzeilige Zeichenkette?', '<<Zeichenkette>>', '"""Zeichenkette"""', '||Zeichenkette||', '**Zeichenkette**', 2, 'easy');
INSERT INTO py_questions VALUES (46, 1, 4, 'Wie bekommt man die Länge einer Zeichenkette?', 'length()', 'size()', 'len()', 'count()', 3, 'easy');
INSERT INTO py_questions VALUES (47, 2, 4, 'Wie konvertiert man eine Liste in eine Zeichenkette?', 'merge()', 'join()', 'append()', 'concat()', 2, 'easy');
INSERT INTO py_questions VALUES (48, 2, 4, 'Wie entfernt man führende und nachfolgende Leerzeichen aus einer Zeichenkette?', 'trim()', 'remove()', 'delete()', 'strip()', 4, 'easy');
INSERT INTO py_questions VALUES (49, 3, 3, 'Wie nennt man die Methode, die ein Objekt in einen Zeichenketten-Darstellung umwandelt?', '__convert__()', '__toString__()', '__repr__()', '__str__()', 4, 'middle');
INSERT INTO py_questions VALUES (50, 3, 3, 'Wie nennt man die Methode, die aufgerufen wird, wenn ein Objekt gelöscht wird?', '__del__()', '__destroy__()', '__remove__()', '__delete__()', 1, 'middle');
INSERT INTO py_questions VALUES (51, 4, 3, 'Welche Bibliothek wird verwendet, um HTTP-Anfragen zu stellen?', 'http', 'urllib', 'socket', 'requests', 4, 'easy');
INSERT INTO py_questions VALUES (52, 4, 3, 'Welche Bibliothek wird zum Testen von Python-Code verwendet?', 'pytest', 'unittest', 'testlib', 'codecheck', 1, 'middle');
INSERT INTO py_questions VALUES (53, 5, 3, 'Welche Ausnahme tritt auf, wenn eine Variable nicht definiert ist?', 'ValueError', 'NameError', 'TypeError', 'AttributeError', 2, 'middle');
INSERT INTO py_questions VALUES (54, 5, 3, 'Welche Ausnahme tritt auf, wenn eine Division durch Null erfolgt?', 'ValueError', 'ArithmeticError', 'MathError', 'ZeroDivisionError', 4, 'middle');
INSERT INTO py_questions VALUES (55, 1, 5, 'Wie erstellt man eine leere Menge?', '{}', 'set()', '()', '[]', 2, 'middle');
INSERT INTO py_questions VALUES (56, 1, 5, 'Welches Schlüsselwort wird verwendet, um eine Bedingung zu prüfen?', 'if', 'for', 'case', 'while', 1, 'easy');
INSERT INTO py_questions VALUES (57, 2, 5, 'Wie nennt man eine unveränderliche Liste?', 'list', 'tuple', 'set', 'dict', 2, 'easy');
INSERT INTO py_questions VALUES (58, 2, 5, 'Wie fügt man ein Schlüssel-Wert-Paar zu einem Wörterbuch hinzu?', 'dict[key] = value', 'dict.insert(key, value)', 'dict.add(key, value)', 'dict.put(key, value)', 1, 'middle');
INSERT INTO py_questions VALUES (59, 3, 4, 'Wie nennt man die Methode, die verwendet wird, um einen Iterator zurückzugeben?', '__yield__()', '__next__()', '__return__()', '__iter__()', 4, 'hight');
INSERT INTO py_questions VALUES (60, 3, 4, 'Wie nennt man die Methode, die verwendet wird, um das nächste Element eines Iterators zurückzugeben?', '__iter__()', '__yield__()', '__return__()', '__next__()', 4, 'hight');
INSERT INTO py_questions VALUES (61, 4, 4, 'Welche Bibliothek wird verwendet, um reguläre Ausdrücke in Python zu verwenden?', 're', 'regex', 'regexp', 'pattern', 1, 'easy');
INSERT INTO py_questions VALUES (62, 4, 4, 'Welche Bibliothek wird zum Bearbeiten von CSV-Dateien verwendet?', 'xlsx', 'excel', 'pandas', 'csv', 4, 'middle');
INSERT INTO py_questions VALUES (63, 5, 4, 'Welche Ausnahme tritt auf, wenn ein ungültiger Typ verwendet wird?', 'IndexError', 'TypeError', 'ValueError', 'AttributeError', 2, 'middle');
INSERT INTO py_questions VALUES (64, 5, 4, 'Welche Ausnahme tritt auf, wenn auf ein nicht existierendes Attribut zugegriffen wird?', 'NameError', 'TypeError', 'ValueError', 'AttributeError', 4, 'middle');
INSERT INTO py_questions VALUES (65, 1, 6, 'Wie ruft man eine Methode eines Objekts auf?', 'object#method()', 'object->method()', 'object.method()', 'object:method()', 3, 'easy');
INSERT INTO py_questions VALUES (66, 1, 6, 'Welche Funktion wird verwendet, um die größte Zahl in einer Liste zu finden?', 'largest()', 'max()', 'top()', 'biggest()', 2, 'easy');
INSERT INTO py_questions VALUES (67, 2, 6, 'Wie konvertiert man eine Liste in ein Set?', 'list()', 'set()', 'dict()', 'tuple()', 2, 'easy');
INSERT INTO py_questions VALUES (68, 2, 6, 'Wie überprüft man, ob ein Schlüssel in einem Wörterbuch existiert?', 'dict.has_key(key)', 'dict.contains(key)', 'key in dict', 'dict.exists(key)', 3, 'middle');
INSERT INTO py_questions VALUES (69, 3, 5, 'Wie nennt man die Methode, die verwendet wird, um ein Attribut eines Objekts zurückzugeben?', '__attr__()', '__getattr__()', '__setattr__()', '__delattr__()', 2, 'hight');
INSERT INTO py_questions VALUES (70, 5, 5, 'Welche Ausnahmen sind für Zugriffe auf indizes einer Liste korrekt?', 'IndexError', 'TypeError', 'KeyError', 'ValueError', (1, 3), 'middle');
INSERT INTO py_questions VALUES (71, 1, 6, 'Wie schreibt man eine mehrzeilige Zeichenkette?', '<<Zeichenkette>>', '"""Zeichenkette"""', '||Zeichenkette||', '**Zeichenkette**', (2, 4), 'easy');
+15
View File
@@ -0,0 +1,15 @@
from customtkinter import *
from PIL import Image
app = CTk()
app.geometry("500x400")
set_appearance_mode("dark")
img = Image.open("images.png")
btn = CTkButton(master=app, text="Click Me", corner_radius=32, fg_color="#C850C0", hover_color="#4158D0", image=CTkImage(dark_image=img, light_image=img))
btn.place(relx=0.5, rely=0.5, anchor="center")
app.mainloop()