programmeren

in python

Jaar 3 - Module 2 - eindopdracht bonus: tkinter

vandaag gaan we...

 

  • Leren hoe je knoppen maakt met tkinter
  • gebruik tkinter voor de eindopdracht

De database opdracht

  • Gebruik, in principe, dezelfde klant en data
  • Bekijk je eind-Excelsheet en maak een verslag:
    • Hoe zou je deze tabellen en formules omzetten naar een database?
    • Welke Excel-dingen kun je nog niet in databases?
    • Zet dan de Excelsheet om naar een sql database

De database opdracht

  • Gebruik, in principe, dezelfde klant en data
  • Bekijk je eind-Excelsheet en maak een verslag:
    • Hoe zou je deze tabellen en formules omzetten naar een database?
    • Welke Excel-dingen kun je nog niet in databases?
    • Zet dan de Excelsheet om naar een sql database
  • Denk na wat voor gegevens je zou willen invoeren in de database
    • Welke gegevens staan er al in?
    • Welke gegevens zouden nog toegevoegd kunnen worden?
    • Maak met Python een interface om dit in te voeren
    • Beschijf ook alle extra's die je hebt gedaan

Fase 1 - Deadline 18 januari

  • Gebruik, in principe, dezelfde klant en data
  • Bekijk je eind-Excelsheet en maak een verslag:
    • Hoe zou je deze tabellen en formules omzetten naar een database?
    • Welke Excel-dingen kun je nog niet in databases?
    • Zet dan de Excelsheet om naar een sql database in repl

De opdracht - Fases

Fase 2 - Deadline 14 februari

 

Denk na wat voor gegevens je zou willen invoeren in de database

  • Welke gegevens staan er al in?
  • Welke gegevens zouden nog toegevoegd kunnen worden?
  • Maak met Python een interface om dit in te voeren

De opdracht - Fases

Python interface

 

  • 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)

Python interface

 

  • input() is de meest basic manier om te communiceren met een gebruiker
     

  • vaker wordt gebruik gemaakt van knoppen en invulschermen

Python interface

 

  • input() is de meest basic manier om te communiceren met een gebruiker
     

  • vaker wordt gebruik gemaakt van knoppen en invulschermen

Python interface

  • knoppen en invulschermen kan je maken met tkinter
     

  • demo

Python interface

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

Python interface

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

Python interface

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

Python interface

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)

Python interface

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

Python interface

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

Python interface

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

Python interface

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

Python interface

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

Python interface

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

Python interface

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

Python interface

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

Python interface

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

Python interface

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

Python interface

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

Python interface

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

Python interface

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

Python interface

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

Tkinter

 

Probeer eerst voorbeelden te begrijpen

  • Voer de code uit
     
  • Probeer regel voor regel te begrijpen wat er gebeurd
     
  • Pas iets aan in de code en bekijk het effect
     
  • Schrijf commentaar bij iedere regel code

Tkinter

 

Voorbeelden

Made with Slides.com