温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Python中Sizegrip控件如何使用

发布时间:2021-07-05 16:07:11 来源:亿速云 阅读:231 作者:Leah 栏目:大数据

本篇文章为大家展示了Python中Sizegrip控件如何使用,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。

首先是构建主窗口。

root = Tk()root.title('Tkinter Sizegrip Demo V1.0')
screen_w = root.winfo_screenwidth()screen_h = root.winfo_screenheight()root.maxsize(width=screen_w, height=screen_h)rw = int(screen_w / 2)rh = int(screen_h / 2)root.geometry('{}x{}+{:g}+{:g}'.format(rw, rh, rw / 2, rh / 2))

代码中除了指定了窗口标题之外,还对窗口进行了居中处理。接下来是构建退出菜单:

top_menu = Menu(root)root.config(menu=top_menu)
file_menu = Menu(top_menu, tearoff=False)top_menu.add_cascade(label='File', menu=file_menu)file_menu.add_command(label="Exit", command=root.quit)

为了方便管理,首先生成一个管理编辑器控件的Frame控件:

edit_area = Frame(root)edit_area.grid(row=1, column=0)

生成Text控件时同时调整了控件的尺寸。由于Text的高度和宽度都是以字符为单位指定,因此多费了不少周折。如果不调大Text的尺寸,当root窗口的尺寸大到某个值的时候,Text就不再跟随窗口的尺寸。

# create text widget.
font = Font(family='Arial', size=15),text = Text(edit_area, font=font, height=80, wrap=NONE)text.config(width=int(text['width']* screen_w / text.winfo_reqwidth()),            height=int(text['height']* screen_h / text.winfo_reqheight()))text.grid(row=0, column=0, sticky='nsew')

text.config的执行结果是将Text控件的大小调整为和屏幕同样大小。接下来构建滚动条控件,都是标准做法。

scroll_ty = Scrollbar(edit_area, orient=VERTICAL, command=text.yview)scroll_ty.grid(row=0, column=1, sticky=N+S)text['yscrollcommand']=scroll_ty.set
scroll_tx = Scrollbar(edit_area, orient=HORIZONTAL, command=text.xview)scroll_tx.grid(row=1, column=0, sticky=E+W)text['xscrollcommand']=scroll_tx.set

Sizegrip本身很简单:

Sizegrip(edit_area).grid(row=1, column=1)

上述内容就是Python中Sizegrip控件如何使用,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注亿速云行业资讯频道。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI