Advertisement
cd62131

tkinter entry

Dec 3rd, 2018
513
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.03 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # coding: utf-8
  3. import tkinter
  4.  
  5.  
  6. class App(tkinter.Frame):
  7.     def __init__(self, master=None):
  8.         super().__init__(master)
  9.         self.master = master
  10.         self.pack()
  11.         self.create()
  12.  
  13.     def create(self):
  14.         a = [[1, 2, 3], ['円', '個', '数']]
  15.         self.s = []
  16.         self.entry = []
  17.         for i, (n, N) in enumerate(zip(*a)):
  18.             tkinter.Label(self, text=f"{n} {N}").grid(column=0, row=i)
  19.             self.s.append(tkinter.StringVar())
  20.             self.entry.append(
  21.                 tkinter.Entry(self, textvariable=self.s[-1]).grid(
  22.                     column=1, row=i))
  23.         self.button = tkinter.Button(
  24.             self, text='join entry', command=self.join_entry)
  25.         self.button.grid(column=0, columnspan=2, row=3)
  26.         self.label = tkinter.Label(self)
  27.         self.label.grid(column=0, columnspan=2, row=4)
  28.  
  29.     def join_entry(self):
  30.         self.label['text'] = '|'.join([ss.get() for ss in self.s])
  31.  
  32.  
  33. App(master=tkinter.Tk()).mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement