77范文网 - 专业文章范例文档资料分享平台

GUI中Button Types and Button Group的介绍

来源:网络收集 时间:2021-09-24 下载这篇文档 手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:或QQ: 处理(尽可能给您提供完整文档),感谢您的支持与谅解。点击这里给我发消息

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

百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说公务员考试GUI中Button Types and Button Group的介绍在线全文阅读。

GUI中Button Types and Button Group的介绍.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印 下载失败或者文档不完整,请联系客服人员解决!
本文链接:https://www.77cn.com.cn/wenku/gongwuyuan/1248728.html(转载请注明文章来源)

相关推荐:

Copyright © 2008-2022 免费范文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ: 邮箱:tiandhx2@hotmail.com
苏ICP备16052595号-18
× 注册会员免费下载(下载后可以自由复制和排版)
注册会员下载
全站内容免费自由复制
注册会员下载
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: