GUI中Button Types and Button Group的介绍

2021-09-24 13:20

网上的对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');

GUI中Button Types and Button Group的介绍.doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:带电粒子在匀强磁场中运动轨迹

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: