Reader small image

You're reading from  Tkinter GUI Application Development Blueprints

Product typeBook
Published inNov 2015
Reading LevelExpert
PublisherPackt
ISBN-139781785889738
Edition1st Edition
Languages
Right arrow
Author (1)
Bhaskar Chaudhary
Bhaskar Chaudhary
author image
Bhaskar Chaudhary

Bhaskar Chaudhary is a professional programmer and information architect. He has a decade of experience in consulting, contracting, and educating in the field of software development. He has worked with a large set of programming languages on various platforms over the years. He is an electronics hobbyist and a musician in his free time.
Read more about Bhaskar Chaudhary

Right arrow

Displaying the line number


Let's work towards showing the line numbers to the left of the Text widget. This will require us to tweak the code at various places. So, before we start coding, let's look at what we are trying to achieve here.

The View menu has a menu item that allows users to choose whether to show line numbers. We only want to show the line numbers if the option is selected, as shown in the following screenshot:

If the option is selected, we need to display the line numbers in the left frame that we created earlier.

The line number should update every time a user enters a new line, deletes a line, cuts or pastes text from the line, performs an undo or a redo operation, opens an existing file, or clicks on the new menu item. In short, the line number should be updated after every activity results in change of content.

Therefore, we need to define a function called on_content_changed(). This function should be called after the definitions of every key press, cut, paste, undo, redo...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Tkinter GUI Application Development Blueprints
Published in: Nov 2015Publisher: PacktISBN-13: 9781785889738

Author (1)

author image
Bhaskar Chaudhary

Bhaskar Chaudhary is a professional programmer and information architect. He has a decade of experience in consulting, contracting, and educating in the field of software development. He has worked with a large set of programming languages on various platforms over the years. He is an electronics hobbyist and a musician in his free time.
Read more about Bhaskar Chaudhary