You can connect to Gradescope to take weekly graded quiz today during the last 15 minutes of the class.
Once you start the quiz you have 15 minutes to finish it.
You can only take this quiz today.
There is not makeup for the weekly quiz because Gradescope does not permit it.
The final exam will be held on Thursday, December 22nd from 3 to 6 PM.
The exam will be given in this room.
If for some reason you are not able to take the Final at the time it will be offered, you MUST send an email to me before the exam so we can make alternative arrangements.
The final will consist of questions like those on the quizzes, along with questions asking you to write short segments of Python code.
60% of the points on this exam will consist of questions from the Ungraded Class Quizzes.
The remaining 40% will come from 4 questions that ask you to write some code.
The last class on Tuesday, December 13th, will be a review session.
You will only be responsible for the material in that review session and the review for the Midterm, which you will find here.
There will be no class on what would normally be the last day of class, Tuesday, May 10th.
But I will be in this classroom at the regular time for any student who needs additional help.
This should give you a week to study for the final.
Although the time alloted for the exam is 3 hours, I would expect that most of you would not need that much time.
The final is a closed book exam.
To prevent cheating, certain rules will be enforced during the exam.
At the end of each semester we offer you the opportunity to say what you think about this course.
What have I done right?
What have I done wrong?
What can I do better?
You are not asked for you name.
So the submissions are anonymous.
I will not see your responses until after I have submitted grades for this course.
We collect this feedback through Course Evaluations.
I will use what you say to make this course better.
To complete the course evalutaion, use the following link .
You have until Wednesday, December 21st, to submit the evaluation.
#! /usr/bin/python3 import tkinter class EmptyWindow: def __init__(self): # Create the main window widget. self.main_window = tkinter.Tk() # Enter the tkinter main loop. tkinter.mainloop() root = EmptyWindow()
#! /usr/bin/python3
import tkinter
class EmptyWindow:
def __init__(self):
self.main_window = tkinter.Tk()
self.main_window.title("Empty Window")
tkinter.mainloop()
root = EmptyWindow()
WIDTHxHEIGHT
#! /usr/bin/python3
import tkinter
class EmptyWindow:
def __init__(self):
self.main_window = tkinter.Tk()
self.main_window.title("Empty Window")
self.main_window.geometry("400x200")
tkinter.mainloop()
root = EmptyWindow()
WIDTHxHEIGHT+X_COORDINATE+Y_COORDINATE
Widget | Description |
---|---|
Button | A button that can cause an action to occur when it is clicked |
Canvas | A rectangular area that can be used to display graphics |
Checkbutton | A button that may be in either the "on" or "off" position |
Entry | An area in which the user may type a single line of input from the keyboard |
Frame | A container that can hold other widgets |
Label | An area that displays one line of text or an image |
Listbox | A list from which the user may select an item |
Menu | A list of menu choices that are displayed when the user clicks a Menu widget |
Menubutton | A menu that is displayed on the screen and may be clicked by the user |
Message | Displays multiple lines of text |
Radiobutton | A widget that can be either selected or deselected. Radiobutton widgets usually appear in groups and allow the user to select one of several options |
Scale | A widget that allows the user to select a value by moving a slider along a track |
Scrollbar | Can be used with some other types of widgets to provide scrolling ability |
Text | A widget that allows the user to enter multiple lines of text input |
Toplevel | A container, like a Frame, but displayed in its own window |
import tkinter class HelloWindow: def __init__(self): self.main_window = tkinter.Tk() self.main_window.title("Hello") self.main_window.geometry("400x200") self.label = tkinter.Label(self.main_window, text="Hello, world!") self.label.pack() tkinter.mainloop() root = HelloWindow()
self.label = tkinter.Label(self.main_window, text="Hello, world!", \ font="times 24 bold")
import tkinter
self.main_window = tkinter.Tk() ... self.label = tkinter.Label(self.main_window, text="Hello, world!", font="times 24 bold") ... tkinter.mainloop()
from tkinter import *
self.main_window = Tk() ... self.label = Label(self.main_window, text="Hello, world!", \ font="times 24 bold") ... mainloop()
self.label = Label(self.main_window, text="Hello, world!", \
font="times 24 bold", fg="blue")
from tkinter import * class ColorWindow: def __init__(self): self.main_window = Tk() self.main_window.title("Colors") self.main_window.geometry("400x200") self.red_label = Label(self.main_window, text="Red text", fg="red") self.red_label.pack() self.orange_label = Label(self.main_window, text="Orange text", fg="orange") self.orange_label.pack() self.yellow_label = Label(self.main_window, text="Yellow text", fg="yellow") self.yellow_label.pack() self.green_label = Label(self.main_window, text="Green text", fg="green") self.green_label.pack() self.blue_label = Label(self.main_window, text="Blue text", fg="blue") self.green_label.pack() self.violet_label = Label(self.main_window, text="Violet text", fg="violet") self.violet_label.pack() self.cyan_label = Label(self.main_window, text="Cyan text", fg="cyan") self.cyan_label.pack() self.magenta_label = Label(self.main_window, text="Magenta text", fg="magenta") self.magenta_label.pack() self.brown_label = Label(self.main_window, text="Brown text", fg="brown") self.brown_label.pack() mainloop() root = ColorWindow()
self.red_label = Label(self.main_window, text="Red text", fg="red") self.red_label.pack() self.orange_label = Label(self.main_window, text="Orange text", fg="orange") self.orange_label.pack() self.yellow_label = Label(self.main_window, text="Yellow text", fg="yellow") self.yellow_label.pack() ...
class ColorWindow: def __init__(self): self.main_window = Tk() self.main_window.title("Colors") self.main_window.geometry("400x200") for color in ["red", "orange", "yellow", "green", "blue", "violet", "magenta", "cyan", "brown"]: self.colored_label(color) mainloop() def colored_label(self, color): label_text = color.capitalize() + " text" self.label = Label(self.main_window, text=label_text, fg=color) self.label.pack()
WIDTHxHEIGHT+X_COORDINATE+Y_COORDINATE
from tkinter import * class CenteredWindow: def __init__(self): self.main_window = Tk() self.main_window.title("Centered") self.main_window.geometry("400x200") screen_width = self.main_window.winfo_screenwidth() screen_height = self.main_window.winfo_screenheight() self.l1 = Label(self.main_window, text=screen_width) self.l1.pack() self.l2 = Label(self.main_window, text=screen_height) self.l2.pack() mainloop() root = CenteredWindow()
y_coordinate = screen_width/2 - window_width/2
from tkinter import * class CenteredWindow: def __init__(self): self.main_window = Tk() self.main_window.title("Centered") self.window_position(400,200) self.label = Label(self.main_window, text="A centered window") self.label.pack() mainloop() def window_position(self, width, height): screen_height = self.main_window.winfo_screenheight() screen_width = self.main_window.winfo_screenwidth() x = screen_width // 2 - width // 2 y = screen_height // 2 - height // 2 self.main_window.geometry(str(width) + "x" + str(height) + "+" + str(x) + "+" + str(y)) root = CenteredWindow()
from tkinter import * class PackTestWindow: def __init__(self): self.root= Tk() self.root.title("Pack Test") mainloop() root = PackTestWindow()
class PackTestWindow:
def __init__(self):
self.root= Tk()
self.root.title("Pack Test")
self.l1 = Label(self.root, text="First label", fg="red")
self.l1.pack()
mainloop()
root = PackTestWindow()
self.l2 = Label(self.root, text="Second label", fg="green") self.l2.pack()
self.l3 = Label(self.root, text="Third label", fg="blue") self.l3.pack()
self.l1 = Label(self.root, text="First label", fg="red") self.l1.pack(side="left") self.l2 = Label(self.root, text="Second label", fg="green") self.l2.pack(side="left") self.l3 = Label(self.root, text="Third label", fg="blue") self.l3.pack(side="left")
class FrameWindow: def __init__(self): self.root= Tk() self.root.title("Frame Test") self.top_frame = Frame(self.root) self.bottom_frame = Frame(self.root)
self.l1 = Label(self.top_frame, text="Red label", fg="red") self.l1.pack(side="top") self.l2 = Label(self.top_frame, text="Green label", fg="green") self.l2.pack(side="top") self.l3 = Label(self.top_frame, text="Blue label", fg="blue") self.l3.pack(side="top") self.l4 = Label(self.bottom_frame, text="Magenta label", fg="magenta") self.l4.pack(side="left") self.l5 = Label(self.bottom_frame, text="Cyan label", fg="cyan") self.l5.pack(side="left")
self.top_frame.pack() self.bottom_frame.pack()
class GridWindow: def __init__(self): self.root= Tk() self.root.title("Grid Test") self.l1 = Label(self.root, text="Red", fg="red") self.l1.grid(row=0, column=0) self.l2 = Label(self.root, text="Green", fg="green") self.l2.grid(row=0, column=1) self.l3 = Label(self.root, text="Blue", fg="blue") self.l3.grid(row=1, column=0) self.l4 = Label(self.root, text="Magenta", fg="magenta") self.l4.grid(row=1, column=1) mainloop()
from tkinter import *
class ButtonWindow:
def __init__(self):
self.root= Tk()
self.root.title("Button Test")
self.button = Button(self.root, text="Quit", command=quit)
self.button.pack()
mainloop()
root = ButtonWindow()
import tkinter.messagebox class ButtonWindow: def __init__(self): self.root= Tk() self.root.title("Button Test") self.button = Button(self.root, \ text="Click for showinfo box", \ command=self.action) self.button.pack() mainloop() def action(self): tkinter.messagebox.showinfo("Show Info", \ "This is a message box created by showinfo")
def action(self): tkinter.messagebox.showwarning("Show Warning", "This is a message box created by showwarning")
def action(self): tkinter.messagebox.showerror("Show Error", "This is a message box created by showerror")
def action(self):
reply = tkinter.messagebox.askquestion("Ask Question", "This is a message box created by askquestion")
tkinter.messagebox.showerror("Result", "You clicked " + reply)