python GUI作业:使用tkinter的重要控件

摘要:python测试开发项目实战-目录题目1:使用tkinter的重要控件 绘制如下菜单:图片.png参考代码:#!/usr/bin/env python3# -*- coding: utf-8 -*-# 技术支撑:https://www.jianshu.com/u/69f40328d4f0 # 技术支

python测试开发项目实战-目录

题目1:使用tkinter的重要控件 绘制如下菜单:

图片.png

参考代码:

#!/usr/bin/env python3# -*- coding: utf-8 -*-# 技术支撑:https://www.songma.com/u/69f40328d4f0 # 技术支撑 https://china-testing.github.io/#  china-testing/python-api-tesing/blob/master/practices/tk/tk3.py# 项目实战探讨QQ群630011153 144081101# CreateDate: 2018-11-29import tkinter as tkroot = tk.Tk()root.title('tkinter控件')#create a frame widget for placing menumy_menu_bar = tk.Frame(root, relief='raised', bd=2)my_menu_bar.pack(fill=tk.X)# Create  Menu Widget 1 and Sub Menu 1my_menu_button = tk.Menubutton(    my_menu_bar,    text='菜单1',)my_menu_button.pack(side=tk.LEFT)#menu widgetmy_menu = tk.Menu(my_menu_button, tearoff=0)my_menu_button['menu'] = my_menumy_menu.add('command', label='子菜单1')  #Add Sub Menu 1# Create  Menu2 and Submenu2menu_button_2 = tk.Menubutton(    my_menu_bar,    text='菜单2',)menu_button_2.pack(side=tk.LEFT)my_menu_2 = tk.Menu(menu_button_2, tearoff=0)menu_button_2['menu'] = my_menu_2my_menu_2.add('command', label='子菜单2')  # Add Sub Menu 2### my_frame_1  and its contents## creating a frame (my_frame_1)my_frame_1 = tk.Frame(root, bd=2, relief=tk.SUNKEN)my_frame_1.pack(side=tk.LEFT)# add label to to my_frame_1tk.Label(my_frame_1, text='标签').pack()#add entry widget to my_frame_1tv = tk.StringVar()  #discussed latertk.Entry(my_frame_1, textvariable=tv).pack()tv.set('I am an entry widget')#add button widget to my_frame_1tk.Button(my_frame_1, text='tk.Button widget').pack()#add check button widget to my_frame_1tk.Checkbutton(my_frame_1, text='Checktk.Button Widget').pack()#add radio buttons to my_frame_1tk.Radiobutton(my_frame_1, text='Radio tk.Button  Un', value=1).pack()tk.Radiobutton(my_frame_1, text='Radio tk.Button  Dos', value=2).pack()tk.Radiobutton(my_frame_1, text='Radio tk.Button  Tres', value=3).pack()#tk.OptionMenu Widgettk.Label(my_frame_1, text='Example of tk.OptionMenu Widget:').pack()tk.OptionMenu(my_frame_1, '', "Option A", "Option B", "Option C").pack()#adding my_image imagetk.Label(my_frame_1, text='Image Fun with Bitmap Class:').pack()my_image = tk.BitmapImage(file="gir.xbm")my_label = tk.Label(my_frame_1, image=my_image)my_label.image = my_image  # keep a reference!my_label.pack()### frame2 and widgets it contains.###create another frame(my_frame_2) to hold a list box, Spinbox Widget,Scale Widget, :my_frame_2 = tk.Frame(root, bd=2, relief=tk.GROOVE)my_frame_2.pack(side=tk.RIGHT)#add Photimage Class Widget to my_frame_2tk.Label(    my_frame_2, text='Image displayed with \nPhotoImage class widget:').pack()dance_photo = tk.PhotoImage(file='dance.gif')dance_photo_label = tk.Label(my_frame_2, image=dance_photo)dance_photo_label.image = dance_photodance_photo_label.pack()#add my_listbox widget to my_frame_2tk.Label(my_frame_2, text='Below is an example of my_listbox widget:').pack()my_listbox = tk.Listbox(my_frame_2, height=4)for line in ['Listbox Choice 1', 'Choice 2', 'Choice 3', 'Choice 4']:  my_listbox.insert(tk.END, line)my_listbox.pack()#spinbox widgettk.Label(my_frame_2, text='Below is an example of spinbox widget:').pack()tk.Spinbox(my_frame_2, values=(1, 2, 4, 8, 10)).pack()#scale widgettk.Scale(    my_frame_2, from_=0.0, to=100.0, label='Scale widget',    orient=tk.HORIZONTAL).pack()#LabelFramelabel_frame = tk.LabelFrame(    my_frame_2, text="LabelFrame Widget", padx=10, pady=10)label_frame.pack(padx=10, pady=10)tk.Entry(label_frame).pack()#message widgettk.Message(my_frame_2, text='I am a Message widget').pack()### tk.Frame 3##my_frame_3 = tk.Frame(root, bd=2, relief=tk.SUNKEN)#text widget and associated tk.Scrollbar widgetmy_text = tk.Text(my_frame_3, height=10, width=40)file_object = open('textcontent.txt', encoding='utf-8')file_content = file_object.read()file_object.close()my_text.insert(tk.END, file_content)my_text.pack(side=tk.LEFT, fill=tk.X, padx=5)#add scrollbar widget to the text widgetmy_scrollbar = tk.Scrollbar(my_frame_3, orient=tk.VERTICAL, command=my_text.yview)my_scrollbar.pack(side=tk.RIGHT, fill=tk.Y)my_text.configure(yscrollcommand=my_scrollbar.set)my_frame_3.pack()### tk.Frame 4###create another frame(my_frame_4)my_frame_4 = tk.Frame(root)my_frame_4.pack()my_canvas = tk.Canvas(my_frame_4, bg='white', width=340, height=80)my_canvas.pack()my_canvas.create_oval(20, 15, 60, 60, fill='red')my_canvas.create_oval(40, 15, 60, 60, fill='grey')my_canvas.create_text(    130, 38, text='I am a tk.Canvas Widget', font=('arial', 8, 'bold'))### A paned window widget##tk.Label(root, text='Below is an example of Paned window widget:').pack()tk.Label(    root,    text='Notice you can adjust the size of each pane by dragging it').pack()my_paned_window_1 = tk.PanedWindow()my_paned_window_1.pack(fill=tk.BOTH, expand=2)left_pane_text = tk.Text(my_paned_window_1, height=6, width=15)my_paned_window_1.add(left_pane_text)my_paned_window_2 = tk.PanedWindow(my_paned_window_1, orient=tk.VERTICAL)my_paned_window_1.add(my_paned_window_2)top_pane_text = tk.Text(my_paned_window_2, height=3, width=3)my_paned_window_2.add(top_pane_text)bottom_pane_text = tk.Text(my_paned_window_2, height=3, width=3)my_paned_window_2.add(bottom_pane_text)root.mainloop()

题目2:如何查看tkinter的tk版本?

参考答案:

tkinter._test()
图片.png

GUI程序设计通常有哪几部分组成?

图片.png

tkinter的重要控件有哪些?

图片.png
  • 全部评论(0)
最新发布的资讯信息
【系统环境|】2FA验证器 验证码如何登录(2024-04-01 20:18)
【系统环境|】怎么做才能建设好外贸网站?(2023-12-20 10:05)
【系统环境|软件环境】梦幻仙域游戏攻略(2023-12-19 10:02)
【系统环境|软件环境】梦幻仙域游戏攻略(2023-12-19 10:02)
【系统环境|】卡帕部落揭秘潮玩新宠,探究玩法(2023-12-14 09:45)
【系统环境|数据库】 潮玩宇宙游戏道具收集方法(2023-12-12 16:13)
【系统环境|】如何开发搭建卡帕部落模式源码(2023-12-12 10:44)
【系统环境|】遥遥领先!青否数字人直播系统5.0发布,支持真人接管实时驱动!(2023-10-12 17:31)
【系统环境|服务器应用】克隆自己的数字人形象需要几步?(2023-09-20 17:13)
【系统环境|】Tiktok登录教程(2023-02-13 14:17)
手机二维码手机访问领取大礼包
返回顶部