c语言登录图形界面代码
时间: 2024-01-18 15:03:05 浏览: 28
抱歉,我是一个语言模型,无法直接提供图形界面代码。但是,你可以使用一些图形界面工具包,如Qt、GTK+、wxWidgets等,来实现一个简单的登录界面。以下是使用Qt实现登录界面的示例代码:
```
#include <QtWidgets/QApplication>
#include <QtWidgets/QWidget>
#include <QtWidgets/QLabel>
#include <QtWidgets/QLineEdit>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QMessageBox>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget window;
window.setWindowTitle("登录");
window.setFixedSize(300, 200); // 固定窗口大小
QLabel *label_username = new QLabel("用户名:", &window);
QLabel *label_password = new QLabel("密码:", &window);
QLineEdit *edit_username = new QLineEdit(&window);
QLineEdit *edit_password = new QLineEdit(&window);
edit_password->setEchoMode(QLineEdit::Password); // 隐藏密码
QPushButton *btn_login = new QPushButton("登录", &window);
label_username->setGeometry(50, 50, 60, 20);
label_password->setGeometry(50, 80, 60, 20);
edit_username->setGeometry(120, 50, 120, 20);
edit_password->setGeometry(120, 80, 120, 20);
btn_login->setGeometry(120, 120, 60, 30);
QObject::connect(btn_login, &QPushButton::clicked, [&](){
QString username = edit_username->text();
QString password = edit_password->text();
if (username == "admin" && password == "123456") {
QMessageBox::information(&window, "登录成功", "欢迎您,管理员!");
} else {
QMessageBox::warning(&window, "登录失败", "用户名或密码错误!");
}
});
window.show();
return app.exec();
}
```
相关推荐
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)