First define the function (shown in interactive mode) >>> def mak(n): ... return lambda x: x + n ... Next, call the function with a value that is stored as n, now the function is refered to as f >>> f = mak(42) then use call f, the parameter acts as x, where what is returned is x + n >>> f(0) 42 >>> f(1) 43 >>> f(10) 52 call mak again to set n with a new value >>> f = mak(142) >>> f(10) 152
Directory list for ./
| filename: | 21_higher_order_functions.pdf |
| filename: | 22_anonymous_functions.pdf |
| filename: | Examples-Command-Line-Arguments.docx |
| filename: | Examples-Command-Line-Arguments.pdf |
| filename: | Examples-Command-Line-Arguments.txt |
| filename: | Examples-file-read-print-loops.docx |
| filename: | Examples-file-read-print-loops.pdf |
| filename: | Examples-file-read-print-loops.txt |
| filename: | button.txt |
| filename: | center-window.php |
| filename: | checkbutton.html |
| filename: | checkbutton.php |
| filename: | cols.py |
| filename: | exam_reviewTasks1_2.py |
| filename: | fib.py |
| filename: | helloWorld.php |
| filename: | higherOrderListOps.py |
| filename: | label.php |
| filename: | lec23.py |
| filename: | maptest-1.py |
| filename: | maptest-2.py |
| filename: | problem-set-5-task-1.py |
| filename: | quit-button.php |
| filename: | rec1.py |
| filename: | rec2.py |
| filename: | sierpinski.py |
| filename: | sierpinski.txt |
| filename: | spiral97.py |
| filename: | spiral98.py |
| filename: | spiral99.py |
| filename: | tk-1.pho |
| filename: | tk-1.php |
| filename: | tk-2.php |
| filename: | tk-2.txt |
| filename: | tk-3.php |
| filename: | tk-4.php |
| filename: | turtle96.py |
| filename: | turtle97.py |
| filename: | turtle98.py |
#!/usr/bin/python import tkinter top = tkinter.Tk() # Code to add widgets will go here... top.mainloop()
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
ZetCode Tkinter tutorial
This script shows a simple window
on the screen.
author: Jan Bodnar
last modified: January 2011
website: www.zetcode.com
"""
from tkinter import Tk, Frame, BOTH
class Example(Frame):
def __init__(self, parent):
Frame.__init__(self, parent, background="white")
self.parent = parent
self.initUI()
def initUI(self):
self.parent.title("Simple")
self.pack(fill=BOTH, expand=1)
def main():
root = Tk()
root.geometry("250x150+300+300")
app = Example(root)
root.mainloop()
if __name__ == '__main__':
main()
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
ZetCode Tkinter tutorial
This script centers a small
window on the screen.
author: Jan Bodnar
last modified: January 2011
website: www.zetcode.com
"""
from tkinter import Tk, Frame, Button, BOTH
# not ttk -> sytle from ttk import Frame, Button, Style
class Example(Frame):
def __init__(self, parent):
Frame.__init__(self, parent)
self.parent = parent
self.initUI()
def initUI(self):
self.parent.title("Quit button")
# self.style = Style()
# self.style.theme_use("default")
self.pack(fill=BOTH, expand=1)
quitButton = Button(self, text="Quit",
command=self.quit)
quitButton.place(x=50, y=50)
def main():
root = Tk()
root.geometry("250x150+300+300")
app = Example(root)
root.mainloop()
if __name__ == '__main__':
main()