Skip to content

Instantly share code, notes, and snippets.

@EricsonWillians
Created November 3, 2015 02:59
Show Gist options
  • Save EricsonWillians/dd67ab87eee46beb0d59 to your computer and use it in GitHub Desktop.
Save EricsonWillians/dd67ab87eee46beb0d59 to your computer and use it in GitHub Desktop.
Simple Multiplication Table with Tkinter for Python 3.x
# multiplication_table.py
#
# Copyright 2015 Ericson Willians (Rederick Deathwill) <EricsonWRP@ERICSONWRP-PC>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
#
#
import tkinter as tk
class App(tk.Frame):
DEFAULT_PADY = 2
def __init__(self, master=None):
tk.Frame.__init__(self, master)
self.config()
self.grid()
self.create_widgets()
def config(self):
self.master.title("x*y")
def create_widgets(self):
top = self.winfo_toplevel()
top.rowconfigure(0, weight=1)
top.columnconfigure(0, weight=1)
self.rowconfigure(0, weight=1)
self.columnconfigure(0, weight=1)
self.result_label = tk.Label(self, text="Input a number: ")
self.result_label.grid(row=0, column=0, pady=App.DEFAULT_PADY, sticky=tk.W + tk.E + tk.N + tk.S)
self.number_entry = tk.Entry(self, justify=tk.RIGHT)
self.number_entry.grid(row=1, column=0, pady=App.DEFAULT_PADY, sticky=tk.W + tk.E + tk.N + tk.S)
self.show_button = tk.Button(self, text="ok", width=4, command=self.update_result)
self.show_button.grid(row=2, column=0, pady=App.DEFAULT_PADY, sticky=tk.SE)
def update_result(self):
self.result_label["text"] = '\n'.join([
"{x}*{y} = {result}".format(x = int(self.number_entry.get()),
y = n, result = int(self.number_entry.get())*n)
for n in range(11)])
if __name__ == '__main__':
App().mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment