Jaar 3 - Module 2 - eindopdracht bonus: tkinter
Fase 1 - Deadline 18 januari
Fase 2 - Deadline 14 februari
Denk na wat voor gegevens je zou willen invoeren in de database
Stel vragen met input()
Bedenk wat iemand allemaal kan antwoorden
naam = input('welke naam wil je invoeren?')
leeftijd = input(f'wat is de leeftijd van {naam}?')
antw = input('wil je de resultaten zien?')
if antw == 'ja':
print(resultaten)
antw = input('wil je de resultaten zien [ja/nee]?')
while antw != 'ja' and antw != 'nee':
print('antwoord astublieft met "ja" of met "nee"')
antw = input('wil je de resultaten zien [ja/nee]?')
if antw == 'ja':
print(resultaten)
input() is de meest basic manier om te communiceren met een gebruiker
input() is de meest basic manier om te communiceren met een gebruiker
knoppen en invulschermen kan je maken met tkinter
from tkinter import *
root = Tk()
root.geometry("300x300")
root.title("Q&A")
def Take_input():
INPUT = inputtxt.get("1.0", "end-1c")
Output.delete(1.0, END)
if(INPUT == "120"):
Output.insert(END, 'Correct')
else:
Output.insert(END, "Wrong answer")
l = Label(text = "What is 24 * 5 ? ")
inputtxt = Text(root, height = 5, width = 25, bg = "light yellow")
Output = Text(root, height = 5, width = 25, bg = "light cyan")
Display = Button(root, height = 2, width = 20, text ="Show",
command = Take_input)
l.pack()
inputtxt.pack()
Display.pack()
Output.pack()
mainloop()
from tkinter import *
root = Tk()
root.geometry("300x300")
root.title("Q&A")
def Take_input():
INPUT = inputtxt.get("1.0", "end-1c")
Output.delete(1.0, END)
if(INPUT == "120"):
Output.insert(END, 'Correct')
else:
Output.insert(END, "Wrong answer")
l = Label(text = "What is 24 * 5 ? ")
inputtxt = Text(root, height = 5, width = 25, bg = "light yellow")
Output = Text(root, height = 5, width = 25, bg = "light cyan")
Display = Button(root, height = 2, width = 20, text ="Show",
command = Take_input)
l.pack()
inputtxt.pack()
Display.pack()
Output.pack()
mainloop()
importeer tkinter
from tkinter import *
root = Tk()
root.geometry("300x300")
root.title("Q&A")
def Take_input():
INPUT = inputtxt.get("1.0", "end-1c")
Output.delete(1.0, END)
if(INPUT == "120"):
Output.insert(END, 'Correct')
else:
Output.insert(END, "Wrong answer")
l = Label(text = "What is 24 * 5 ? ")
inputtxt = Text(root, height = 5, width = 25, bg = "light yellow")
Output = Text(root, height = 5, width = 25, bg = "light cyan")
Display = Button(root, height = 2, width = 20, text ="Show",
command = Take_input)
l.pack()
inputtxt.pack()
Display.pack()
Output.pack()
mainloop()
start een window
from tkinter import *
root = Tk()
root.geometry("300x300")
root.title("Q&A")
def Take_input():
INPUT = inputtxt.get("1.0", "end-1c")
Output.delete(1.0, END)
if(INPUT == "120"):
Output.insert(END, 'Correct')
else:
Output.insert(END, "Wrong answer")
l = Label(text = "What is 24 * 5 ? ")
inputtxt = Text(root, height = 5, width = 25, bg = "light yellow")
Output = Text(root, height = 5, width = 25, bg = "light cyan")
Display = Button(root, height = 2, width = 20, text ="Show",
command = Take_input)
l.pack()
inputtxt.pack()
Display.pack()
Output.pack()
mainloop()
bepaal de grootte (pixels)
from tkinter import *
root = Tk()
root.geometry("300x300")
root.title("Q&A")
def Take_input():
INPUT = inputtxt.get("1.0", "end-1c")
Output.delete(1.0, END)
if(INPUT == "120"):
Output.insert(END, 'Correct')
else:
Output.insert(END, "Wrong answer")
l = Label(text = "What is 24 * 5 ? ")
inputtxt = Text(root, height = 5, width = 25, bg = "light yellow")
Output = Text(root, height = 5, width = 25, bg = "light cyan")
Display = Button(root, height = 2, width = 20, text ="Show",
command = Take_input)
l.pack()
inputtxt.pack()
Display.pack()
Output.pack()
mainloop()
kies een titel
from tkinter import *
root = Tk()
root.geometry("300x300")
root.title("Q&A")
def Take_input():
INPUT = inputtxt.get("1.0", "end-1c")
Output.delete(1.0, END)
if(INPUT == "120"):
Output.insert(END, 'Correct')
else:
Output.insert(END, "Wrong answer")
l = Label(text = "What is 24 * 5 ? ")
inputtxt = Text(root, height = 5, width = 25, bg = "light yellow")
Output = Text(root, height = 5, width = 25, bg = "light cyan")
Display = Button(root, height = 2, width = 20, text ="Show",
command = Take_input)
l.pack()
inputtxt.pack()
Display.pack()
Output.pack()
mainloop()
Maak een functie
from tkinter import *
root = Tk()
root.geometry("300x300")
root.title("Q&A")
def Take_input():
INPUT = inputtxt.get("1.0", "end-1c")
Output.delete(1.0, END)
if(INPUT == "120"):
Output.insert(END, 'Correct')
else:
Output.insert(END, "Wrong answer")
l = Label(text = "What is 24 * 5 ? ")
inputtxt = Text(root, height = 5, width = 25, bg = "light yellow")
Output = Text(root, height = 5, width = 25, bg = "light cyan")
Display = Button(root, height = 2, width = 20, text ="Show",
command = Take_input)
l.pack()
inputtxt.pack()
Display.pack()
Output.pack()
mainloop()
Haal input op
Haal input op
from tkinter import *
root = Tk()
root.geometry("300x300")
root.title("Q&A")
def Take_input():
INPUT = inputtxt.get("1.0", "end-1c")
Output.delete(1.0, END)
if(INPUT == "120"):
Output.insert(END, 'Correct')
else:
Output.insert(END, "Wrong answer")
l = Label(text = "What is 24 * 5 ? ")
inputtxt = Text(root, height = 5, width = 25, bg = "light yellow")
Output = Text(root, height = 5, width = 25, bg = "light cyan")
Display = Button(root, height = 2, width = 20, text ="Show",
command = Take_input)
l.pack()
inputtxt.pack()
Display.pack()
Output.pack()
mainloop()
verwijder output
from tkinter import *
root = Tk()
root.geometry("300x300")
root.title("Q&A")
def Take_input():
INPUT = inputtxt.get("1.0", "end-1c")
Output.delete(1.0, END)
if(INPUT == "120"):
Output.insert(END, 'Correct')
else:
Output.insert(END, "Wrong answer")
l = Label(text = "What is 24 * 5 ? ")
inputtxt = Text(root, height = 5, width = 25, bg = "light yellow")
Output = Text(root, height = 5, width = 25, bg = "light cyan")
Display = Button(root, height = 2, width = 20, text ="Show",
command = Take_input)
l.pack()
inputtxt.pack()
Display.pack()
Output.pack()
mainloop()
check het antwoord
from tkinter import *
root = Tk()
root.geometry("300x300")
root.title("Q&A")
def Take_input():
INPUT = inputtxt.get("1.0", "end-1c")
Output.delete(1.0, END)
if(INPUT == "120"):
Output.insert(END, 'Correct')
else:
Output.insert(END, "Wrong answer")
l = Label(text = "What is 24 * 5 ? ")
inputtxt = Text(root, height = 5, width = 25, bg = "light yellow")
Output = Text(root, height = 5, width = 25, bg = "light cyan")
Display = Button(root, height = 2, width = 20, text ="Show",
command = Take_input)
l.pack()
inputtxt.pack()
Display.pack()
Output.pack()
mainloop()
laat "correct" zien
from tkinter import *
root = Tk()
root.geometry("300x300")
root.title("Q&A")
def Take_input():
INPUT = inputtxt.get("1.0", "end-1c")
Output.delete(1.0, END)
if(INPUT == "120"):
Output.insert(END, 'Correct')
else:
Output.insert(END, "Wrong answer")
l = Label(text = "What is 24 * 5 ? ")
inputtxt = Text(root, height = 5, width = 25, bg = "light yellow")
Output = Text(root, height = 5, width = 25, bg = "light cyan")
Display = Button(root, height = 2, width = 20, text ="Show",
command = Take_input)
l.pack()
inputtxt.pack()
Display.pack()
Output.pack()
mainloop()
laat "Wrong answer" zien
from tkinter import *
root = Tk()
root.geometry("300x300")
root.title("Q&A")
def Take_input():
INPUT = inputtxt.get("1.0", "end-1c")
Output.delete(1.0, END)
if(INPUT == "120"):
Output.insert(END, 'Correct')
else:
Output.insert(END, "Wrong answer")
l = Label(text = "What is 24 * 5 ? ")
inputtxt = Text(root, height = 5, width = 25, bg = "light yellow")
Output = Text(root, height = 5, width = 25, bg = "light cyan")
Display = Button(root, height = 2, width = 20, text ="Show",
command = Take_input)
l.pack()
inputtxt.pack()
Display.pack()
Output.pack()
mainloop()
stel de vraag
from tkinter import *
root = Tk()
root.geometry("300x300")
root.title("Q&A")
def Take_input():
INPUT = inputtxt.get("1.0", "end-1c")
Output.delete(1.0, END)
if(INPUT == "120"):
Output.insert(END, 'Correct')
else:
Output.insert(END, "Wrong answer")
l = Label(text = "What is 24 * 5 ? ")
inputtxt = Text(root, height = 5, width = 25, bg = "light yellow")
Output = Text(root, height = 5, width = 25, bg = "light cyan")
Display = Button(root, height = 2, width = 20, text ="Show",
command = Take_input)
l.pack()
inputtxt.pack()
Display.pack()
Output.pack()
mainloop()
afmetingen en kleur input box
from tkinter import *
root = Tk()
root.geometry("300x300")
root.title("Q&A")
def Take_input():
INPUT = inputtxt.get("1.0", "end-1c")
Output.delete(1.0, END)
if(INPUT == "120"):
Output.insert(END, 'Correct')
else:
Output.insert(END, "Wrong answer")
l = Label(text = "What is 24 * 5 ? ")
inputtxt = Text(root, height = 5, width = 25, bg = "light yellow")
Output = Text(root, height = 5, width = 25, bg = "light cyan")
Display = Button(root, height = 2, width = 20, text ="Show",
command = Take_input)
l.pack()
inputtxt.pack()
Display.pack()
Output.pack()
mainloop()
afmetingen en kleur output box
from tkinter import *
root = Tk()
root.geometry("300x300")
root.title("Q&A")
def Take_input():
INPUT = inputtxt.get("1.0", "end-1c")
Output.delete(1.0, END)
if(INPUT == "120"):
Output.insert(END, 'Correct')
else:
Output.insert(END, "Wrong answer")
l = Label(text = "What is 24 * 5 ? ")
inputtxt = Text(root, height = 5, width = 25, bg = "light yellow")
Output = Text(root, height = 5, width = 25, bg = "light cyan")
Display = Button(root, height = 2, width = 20, text ="Show",
command = Take_input)
l.pack()
inputtxt.pack()
Display.pack()
Output.pack()
mainloop()
Maak een button
from tkinter import *
root = Tk()
root.geometry("300x300")
root.title("Q&A")
def Take_input():
INPUT = inputtxt.get("1.0", "end-1c")
Output.delete(1.0, END)
if(INPUT == "120"):
Output.insert(END, 'Correct')
else:
Output.insert(END, "Wrong answer")
l = Label(text = "What is 24 * 5 ? ")
inputtxt = Text(root, height = 5, width = 25, bg = "light yellow")
Output = Text(root, height = 5, width = 25, bg = "light cyan")
Display = Button(root, height = 2, width = 20, text ="Show",
command = Take_input)
l.pack()
inputtxt.pack()
Display.pack()
Output.pack()
mainloop()
als de knop wordt ingedrukt, voer de functie "Take_input" uit
from tkinter import *
root = Tk()
root.geometry("300x300")
root.title("Q&A")
def Take_input():
INPUT = inputtxt.get("1.0", "end-1c")
Output.delete(1.0, END)
if(INPUT == "120"):
Output.insert(END, 'Correct')
else:
Output.insert(END, "Wrong answer")
l = Label(text = "What is 24 * 5 ? ")
inputtxt = Text(root, height = 5, width = 25, bg = "light yellow")
Output = Text(root, height = 5, width = 25, bg = "light cyan")
Display = Button(root, height = 2, width = 20, text ="Show",
command = Take_input)
l.pack()
inputtxt.pack()
Display.pack()
Output.pack()
mainloop()
voeg label, inputveld, knop en outputveld toe aan je applicatie
from tkinter import *
root = Tk()
root.geometry("300x300")
root.title("Q&A")
def Take_input():
INPUT = inputtxt.get("1.0", "end-1c")
Output.delete(1.0, END)
if(INPUT == "120"):
Output.insert(END, 'Correct')
else:
Output.insert(END, "Wrong answer")
l = Label(text = "What is 24 * 5 ? ")
inputtxt = Text(root, height = 5, width = 25, bg = "light yellow")
Output = Text(root, height = 5, width = 25, bg = "light cyan")
Display = Button(root, height = 2, width = 20, text ="Show",
command = Take_input)
l.pack()
inputtxt.pack()
Display.pack()
Output.pack()
mainloop()
Start de applicatie
Probeer eerst voorbeelden te begrijpen