- Tkinter GUI Application Development Blueprints(Second Edition)
- Bhaskar Chaudhary
- 141字
- 2021-06-24 18:35:09
Implementing the Select All feature
We know that Tkinter has a built-in sel tag that applies a selection to a given text range. We want to apply this tag to the entire text in the widget.
We can simply define a function to handle this, as follows (2.05.py):
def select_all(event=None):
content_text.tag_add('sel', '1.0', 'end')
return "break"
After doing this, add a callback to the Select All menu item:
edit_menu.add_command(label='Select All', underline=7, accelerator='Ctrl+A', command=select_all)
We also need to bind the function to the Ctrl + A keyboard shortcut. We do this by using the following key bindings (2.05.py):
content_text.bind('<Control-A>', select_all)
content_text.bind('<Control-a>', select_all)
The coding of the Select All feature is complete. To try it out, add some text to the text widget and then click on the menu item, Select All, or use Ctrl + A (accelerator shortcut key).
推薦閱讀
- Progressive Web Apps with React
- C++程序設(shè)計(第3版)
- 微服務(wù)與事件驅(qū)動架構(gòu)
- React Native Cookbook
- Bulma必知必會
- ASP.NET 3.5程序設(shè)計與項目實踐
- App Inventor創(chuàng)意趣味編程進階
- Scratch3.0趣味編程動手玩:比賽訓(xùn)練營
- R數(shù)據(jù)科學(xué)實戰(zhàn):工具詳解與案例分析
- Neo4j 3.x入門經(jīng)典
- Learning Shiny
- Spring Boot從入門到實戰(zhàn)
- Three.js Essentials
- 人件集:人性化的軟件開發(fā)
- Java與Android移動應(yīng)用開發(fā):技術(shù)、方法與實踐