Code: Select all
import Tkinter as tk
from Tkinter import *
root = tk.Tk()
root.geometry("200x100")
e = Entry(root, width=10, background='white', textvariable=file, justify=CENTER, font='-weight bold')
e.grid(padx=10, pady=5, row=17, column=1, sticky='W,E,N,S')
root.mainloop()
Code: Select all
try:
# Python2
import Tkinter as tk
except ImportError:
# Python3
import tkinter as tk
# needs Python25 or higher
from functools import partial
def click(btn):
# test the button command click
s = "Button %s clicked" % btn
boot.title(s)
boot = tk.Tk()
boot['bg'] = 'green'
# create a labeled frame for the keypad buttons
# relief='groove' and labelanchor='nw' are default
lf = tk.LabelFrame(boot, text=" keypad ", bd=3)
lf.pack(padx=15, pady=10)
# typical calculator button layout
btn_list = [
'7', '8', '9',
'4', '5', '6',
'1', '2', '3',
'0', 'Close', 'Del']
# create and position all buttons with a for-loop
# r, c used for row, column grid values
r = 1
c = 0
n = 0
# list(range()) needed for Python3
btn = list(range(len(btn_list)))
for label in btn_list:
# partial takes care of function and argument
cmd = partial(click, label)
# create the button
btn[n] = tk.Button(lf, text=label, width=10, height=5, command=cmd)
# position the button
btn[n].grid(row=r, column=c)
# increment button index
n += 1
# update row/column position
c += 1
if c == 3:
c = 0
r += 1
boot.mainloop()