Tk Tutorial - 4. Tk Concepts

Widgets

Widgets are all the things that you see onscreen. In our example, we had a button, an entry, a few labels, and a frame. Others are things like checkboxes, tree views, scrollbars, text areas, and so on. Widgets are what are often referred to as "controls"; you'll also often see them referred to as "windows", particularly in Tk's documentation, a holdover from its X11 roots (so under that terminology, both a toplevel window and things like a button would be called windows).

Each separate widget is a Python object. When creating a widget, you must pass its parent as a parameter to the widget creation function. The only exception is the "root" window, which is the toplevel window that will contain everything else. That is automatically created, and it does not have a parent.

Configuration Options

% python
>>> from tkinter import *
>>> from tkinter import ttk
>>> root = Tk()
create a button, passing two options:
>>> button = ttk.Button(root, text="Hello", command="buttonpressed")
>>> button.grid()
check the current value of the text option:
>>> button['text']
'Hello'
change the value of the text option:
>>> button['text'] = 'goodbye'
another way to do the same thing:
>>> button.configure(text='goodbye')
check the current value of the text option:
>>> button['text']
'goodbye'
get all information about the text option:
>>> button.configure('text')
('text', 'text', 'Text', '', 'goodbye')
get information on all options for this widget:
>>> button.configure()
{'cursor': ('cursor', 'cursor', 'Cursor', '', ''), 'style': ('style', 'style', 'Style', '', ''), 
'default': ('default', 'default', 'Default', <index object at 0x00DFFD10>, <index object at 0x00DFFD10>), 
'text': ('text', 'text', 'Text', '', 'goodbye'), 'image': ('image', 'image', 'Image', '', ''), 
'class': ('class', '', '', '', ''), 'padding': ('padding', 'padding', 'Pad', '', ''), 
'width': ('width', 'width', 'Width', '', ''), 
'state': ('state', 'state', 'State', <index object at 0x0167FA20>, <index object at 0x0167FA20>), 
'command': ('command', 'command' , 'Command', '', 'buttonpressed'), 
'textvariable': ('textvariable', 'textVariable', 'Variable', '', ''), 
'compound': ('compound', 'compound', 'Compound', <index object at 0x0167FA08>, <index object at 0x0167FA08>), 
'underline': ('underline', 'underline', 'Underline', -1, -1), 
'takefocus': ('takefocus', 'takeFocus', 'TakeFocus', '', 'ttk::takefocus')}

Geometry Management

In our example, this positioning was accomplished by the"grid" command,

The geometry manager will ask each slave widget for its natural size, or how large it would ideally like to be displayed.It then takes that information and combines it with any parameters provided by the program when it asks the geometrymanager to manage that particular slave widget. In our example, we passed grid a"column" and"row" number for each widget,which indicated the relative position of the widget with respect to others, and also a"sticky" parameter to suggesthow the widget should be aligned or possibly stretched. We also used"columnconfigure" and "rowconfigure" to indicatethe columns and rows we'd like to have expand if there is extra space available in the window. Of course, all theseparameters are specific to grid; other geometry managers would use different ones.

Event Handling

Command Callbacks

For those events that are pretty much essential to customize (what good is a button without somethinghappening when you press it?), the widget will provide acallback as a widget configuration option.We saw this in the example with the"command" option of the button.

Event Bindings

For events that don't have a command callback associated with them, you can use Tk's "bind" to capture any event, and then (like with callbacks) execute an arbitrary piece of code.

from tkinter import *
from tkinter import ttk
root = Tk()
l =ttk.Label(root, text="Starting...")
l.grid()
l.bind('<Enter>', lambda e: l.configure(text='Moved mouse inside'))
l.bind('<Leave>', lambda e: l.configure(text='Moved mouse outside'))
l.bind('<1>', lambda e: l.configure(text='Clicked left mouse button'))
l.bind('<Double-1>', lambda e: l.configure(text='Double clicked'))
l.bind('<B3-Motion>', lambda e: l.configure(text='right button drag to %d,%d' % (e.x, e.y)))
root.mainloop()
from: http://www.tkdocs.com/tutorial/concepts.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
ug871-vivado-high-level-synthesis-tutorial.pdf是有关Vivado高级综合教程的文档。该文档提供了使用Vivado高级综合工具的指南和教程,以帮助开发人员更高效地进行数字设计。 Vivado是赛灵思公司开发的综合工具套件,用于设计和实现数字电路。高级综合是一种将高级语言(如C或C++)转换为硬件描述语言(如VHDL或Verilog)的技术。它使开发人员能够使用更高级的语言进行设计,并将其转换为硬件电路,从而加快设计过程的速度。 在ug871-vivado-high-level-synthesis-tutorial.pdf中,开发人员将学习如何使用Vivado高级综合工具来创建和转换高级语言设计。文档以简单易懂的方式介绍了Vivado高级综合工具的基本概念和操作步骤。 该教程包含以下主要内容: 1. 介绍了高级综合的基本原理和优势,以及该技术可以加快设计速度的原因。 2. 解释了Vivado高级综合工具的功能和特点,以及如何进行安装和配置。 3. 提供了使用Vivado高级综合工具进行设计的具体步骤和操作指南。其中包括创建高级语言设计文件、设定综合目标和选项、运行综合和优化过程等。 4. 展示了如何生成和验证转换后的硬件电路,并进行仿真和测试。 5. 提供了一些示例案例,帮助开发人员更好地理解和应用Vivado高级综合工具。 通过学习和应用ug871-vivado-high-level-synthesis-tutorial.pdf中的内容,开发人员可以更有效地利用Vivado高级综合工具进行数字设计。这将使他们在开发过程中节省时间和精力,并且能够更快地实现设计目标。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值