-
Notifications
You must be signed in to change notification settings - Fork 2
Tkinter
Gregory Morrison edited this page Feb 5, 2023
·
3 revisions
My adventure with Tcl/Tk led me to compare it to my go-to scripting language, Python. Here is the simplest version of Euler1 in Python's port of Tk, Tkinter, a platform-independent GUI toolkit introduced in the mid '90s. I have to say, there really is no comparison - as much as I love me some Python, Tkinter requires 13 lines to display the simplest HelloWorld, whereas Tcl/Tk requires only two. However, Tcl's version of the Euler1 algorithm took 7 lines while Python's took 2. And it took me probably five minutes to write this. So overall, it's a tie:
#!/usr/bin/python
# Euler1 in Tkinter
from Tkinter import *
def euler1(x):
return sum(i for i in range(x) if i%3==0 or i%5==0)
class Application(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
self.QUIT = Button(self)
self.QUIT["text"] = euler1(1000)
self.QUIT["command"] = self.quit
self.QUIT.pack({"side": "left"})
self.pack()
root = Tk()
app = Application(master=root)
app.mainloop()
root.destroy()
To run, simply call your script:
$ euler1.tk.py
And here is the result:
Return home