vendredi 29 mai 2015

How to save counter of entries in str and show it in Text field?

Using such example i want to count number of entries. And represent string with number of entries in Text field. Like, for example:

1: number of entries(1)
21: number of entries(2)
...

Where should i put my counter variable?

import random
from tkinter import *

class MyApp(Frame):

    def __init__(self, master):
        super(MyApp, self).__init__(master)
        self.grid()
        self.create_widgets()        

    def create_widgets(self):

        Label(self, text = 'Your number:').grid(row = 0, column = 0, sticky = W)
        self.num_ent = Entry(self)
        self.num_ent.grid(row = 0, column = 1, sticky = W)
        Button(self, text = 'Check', command = self.update).grid(row = 0, column = 2, sticky = W)
        self.user_text = Text(self, width = 50, height = 40, wrap = WORD)
        self.user_text.grid(row = 2, column = 0, columnspan = 3)

    def update(self):

        guess = self.num_ent.get()
        guess += '\n'
        self.user_text.insert(0.0, guess)

root = Tk()
root.geometry('410x200')
root.title('Entries counter')
app = MyApp(root)
root.mainloop()

Aucun commentaire:

Enregistrer un commentaire