教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 文库大全 > 求职职场 >

GUI中Button Types and Button Group的介绍

来源:网络收集 时间:2026-07-08
导读: 网上的对GUI控件的介绍! MATLAB GUI Tutorial - Button Types and Button Group 03 Nov 2007 Quan Quach 93 comments 25,002 views Introduction In this three-part Matlab GUI Tutorial, you will learn how to use the different types of buttons availa

网上的对GUI控件的介绍!

MATLAB GUI Tutorial - Button Types and Button Group

03 Nov 2007 Quan Quach 93 comments 25,002 views

Introduction

In this three-part Matlab GUI Tutorial, you will learn how to use the

different types of buttons available within Matlab GUIs. These button

types are: push button, radio button, check box, and toggle buttons. In addition, you will learn how to use the button panel to control a group of buttons.

This tutorial is written for those with little or no experience creating a Matlab GUI (Graphical User Interface). If you re new to creating GUIs in Matlab, you should visit this tutorial first. Basic knowledge of Matlab is recommended. Matlab version 2007a is used in writing this tutorial. Both earlier versions and new versions should be compatible as well (as long as it isan t too outdated). Let s get started! Part One: The Pushbutton

The push button is a very simple component. When the user clicks on a push button, it causes an action to occur. This action is dictated by the code that is programmed in the push button s callback function. In this part of the tutorial, we will program the push button to display some text when it is pressed.

1. First, we are going to create the visual aspect of the GUI. Open up Matlab. Go to the command window and type in guide.

网上的对GUI控件的介绍!

2. You should see the following screen appear. Choose the first option Blank

GUI (Default).

3.

on

4. Click on and add one Static Text component to the GUI figure. Next, click and add one Push button component onto the GUI figure. Double click the Static Text component to bring up the Property Inspector.

Change the String property so that there is nothing inside. Change the Tag property to display_staticText. Similarly, double click on the Pushbutton component and change the String property to Display Text! and change the Tag property to displayText_pushbutton.

网上的对GUI控件的介绍!

5.

Here

s what your figure should look like after you add the components and modify them.

6.

7. Save your GUI wherever you please with your desired filename. Now, we are going to write the code for the GUI. When you save your GUI,

Matlab automatically generates an .m file to go along with the figure that you just put together. The .m file is where we attach the appropriate code to the callback of each component. For the purposes of this tutorial, we are primarily concerned only with the callback functions. You don t have to worry about any of the other function types.

Open up the .m file that was automatically generated when you saved your GUI. In the Matlab editor, click on the icon, which will bring up a list of the functions

网上的对GUI控件的介绍!

within the .m file. Select displayText_pushbutton_Callback.

Add the following code to the function:

%display "Hello Wordl!" in the static text component when the

%pushbutton is pressed

set(handles.display_staticText,'String'

,'Hello World!');

8. Now that we ve completed both the visual and code aspects of the GUI, its

time to run the GUI to make sure it works before we move on. From the m-file editor, you can click on the icon to save and run the GUI. Alternatively, from the GUIDE

to launch the GUI. The GUI should appear once you editor, you can click on the

on the GUI. click the icon. Now try clicking on the button to make sure that Hello World! appears

And that s it. Those are the basics of using the Push button component. Now we re ready to move onto the Check box component.

Part Two: The Check Box

The Check Box component has two states, checked and unchecked. These

components are usually used to control options that can be turned on and off. In this part of the tutorial, we will add the functionality of making the display text become bold or unbolded.

网上的对GUI控件的介绍!

1. The first thing we need to do is to add a Check Box Component to the GUI

figure that we were just working with. So if you closed GUIDE, reopen it again. Once you have GUIDE opened again, Click on

the GUI figure. and add one Check Box component to

2.

Double click the Check Box component to bring up the Property Inspector. Change the String property to Bold. Change the Tag property to bold_checkbox.

3.

Here s what your figure should look like after you add the Check Box component and modify it.

4.

5. Add the following code to the bold_checkbox_Callback function: %checkboxStatus = 0, if the box is unchecked,

网上的对GUI控件的介绍!

6.

7.

8.

9.

10.

11.

12.

13.

end %checkboxStatus = 1, if the box is checked checkboxStatus = get(handles.bold_checkbox,'Value'); if(checkboxStatus

) %if box is checked, text is set to bold set(handles.display_staticText,'FontWeight' , 'bold'); else %if box is unchecked, text is set to normal set(handles.display_staticText,'FontWeight', 'normal');

Note: The bold_checkbox_Callback function triggers when the user activates the check box AND when the user deactivates the check box.

14. Now that we ve completed both the visual and code aspects of the GUI, its

time to run the GUI to make sure it works before we move on. Try checking and unchecking the Check Box component to make sure that the text “Hello World!” is being bolded and unbolded.

And that s it. Those are the basics of using the Check Box component. Now we re ready to move onto the Button Group, which is the most challenging part of this tutorial.

Part Three: Radio Buttons, Toggle Buttons, and Button Group Panel

Radio buttons and Toggle buttons are used ex …… 此处隐藏:13184字,全部文档内容请下载后查看。喜欢就下载吧 ……

GUI中Button Types and Button Group的介绍.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/wenku/1703486.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)