首页 文章 精选 留言 我的

精选列表

搜索[腾讯云双十一抄作业],共10000篇文章
优秀的个人博客,低调大师

[雪峰磁针石博客]python GUI作业:使用tkinter的重要控件

python测试开发项目实战-目录 python工具书籍下载-持续更新 题目1:使用tkinter的重要控件 绘制如下菜单: 参考代码: #!/usr/bin/env python3 # -*- coding: utf-8 -*- # 技术支持:https://www.jianshu.com/u/69f40328d4f0 # 技术支持 https://china-testing.github.io/ # https://github.com/china-testing/python-api-tesing/blob/master/practices/tk/tk3.py # 项目实战讨论QQ群630011153 144081101 # CreateDate: 2018-11-29 import tkinter as tk root = tk.Tk() root.title('tkinter控件') #create a frame widget for placing menu my_menu_bar = tk.Frame(root, relief='raised', bd=2) my_menu_bar.pack(fill=tk.X) # Create Menu Widget 1 and Sub Menu 1 my_menu_button = tk.Menubutton( my_menu_bar, text='菜单1', ) my_menu_button.pack(side=tk.LEFT) #menu widget my_menu = tk.Menu(my_menu_button, tearoff=0) my_menu_button['menu'] = my_menu my_menu.add('command', label='子菜单1') #Add Sub Menu 1 # Create Menu2 and Submenu2 menu_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_2 my_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_1 tk.Label(my_frame_1, text='标签').pack() #add entry widget to my_frame_1 tv = tk.StringVar() #discussed later tk.Entry(my_frame_1, textvariable=tv).pack() tv.set('I am an entry widget') #add button widget to my_frame_1 tk.Button(my_frame_1, text='tk.Button widget').pack() #add check button widget to my_frame_1 tk.Checkbutton(my_frame_1, text='Checktk.Button Widget').pack() #add radio buttons to my_frame_1 tk.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 Widget tk.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 image tk.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_2 tk.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_photo dance_photo_label.pack() #add my_listbox widget to my_frame_2 tk.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 widget tk.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 widget tk.Scale( my_frame_2, from_=0.0, to=100.0, label='Scale widget', orient=tk.HORIZONTAL).pack() #LabelFrame label_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 widget tk.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 widget my_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 widget my_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() GUI程序设计通常有哪几部分组成? tkinter的重要控件有哪些?

优秀的个人博客,低调大师

[雪峰磁针石博客]python绘图作业:使用pygame库画房子

python测试开发项目实战-目录 python工具书籍下载-持续更新 使用pygame库画如下房子 参考资料 本文最新版本地址 本文涉及的python测试开发库 谢谢点赞! 本文相关海量书籍下载 代码 #!/usr/bin/python3 # -*- coding: utf-8 -*- # 技术支持:https://www.jianshu.com/u/69f40328d4f0 # 技术支持 https://china-testing.github.io/ # https://github.com/china-testing/python-api-tesing/blob/master/practices/pygame_house.py # 项目实战讨论QQ群630011153 144081101 # CreateDate: 2018-12-01 import pygame pygame.init() screen = pygame.display.set_mode((640,480)) #used http://colorpicker.com/ to find RGB colors def draw_tree(x,y): #tree trunk (50 wide and 100 tall) pygame.draw.rect(screen,(117,90,0),(x,y-100,50,100)) #leaves are a circle pygame.draw.circle(screen,(27,117,0),(x+25,y-120),50) def draw_house(x,y): #pink house pygame.draw.rect(screen,(255,171,244),(x,y-180,200,180)) #brown door pygame.draw.rect(screen,(89,71,0),(x+80,y-60,40,60)) #yellow door knob pygame.draw.circle(screen,(255,204,0),(x+112,y-30),4) #triangle roof pygame.draw.polygon(screen, (125,125,125), ( (x,y-180),(x+100,y-250),(x+200,y-180) ) ) draw_window(x+20,y-90) draw_window(x+130,y-90) def draw_window(x,y): #glass pygame.draw.rect(screen,(207,229,255),(x,y-50,50,50)) #frame pygame.draw.rect(screen,(0,0,0),(x,y-50,50,50),5) pygame.draw.rect(screen,(0,0,0),(x+23,y-50,5,50)) pygame.draw.rect(screen,(0,0,0),(x,y-27,50,5)) #this function is able to draw clouds of different sizes def draw_cloud(x,y,size): #put int() around any multiplications by decimals to get rid of this warning: #DeprecationWarning: integer argument expected, got float pygame.draw.circle(screen,(255,255,255),(x,y),int(size*.5)) pygame.draw.circle(screen,(255,255,255),(int(x+size*.5),y),int(size*.6)) pygame.draw.circle(screen,(255,255,255),(x+size,int(y-size*.1)),int(size*.4)) #green ground pygame.draw.rect(screen,(0,160,3),(0,400,640,80)) #light blue sky pygame.draw.rect(screen,(135,255,255),(0,0,640,400)) draw_tree(60,400) #x and y location are the bottom left of tree trunk draw_tree(550,400) draw_house(225,400) draw_cloud(60,120,80) draw_cloud(200,50,40) draw_cloud(450,100,120) pygame.display.flip() running = True while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False pygame.quit()

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册