Python 弹出输入框并获取输入值的示例
最编程
2024-04-13 14:37:54
...
使用自带的Tkinter模块,简单的弹输入框示例,返回输入值
from Tkinter import * import tkMessageBox def getInput(title, message): def return_callback(event): print('quit...') root.quit() def close_callback(): tkMessageBox.showinfo('message', 'no click...') root = Tk(className=title) root.wm_attributes('-topmost', 1) screenwidth, screenheight = root.maxsize() width = 300 height = 100 size = '%dx%d+%d+%d' % (width, height, (screenwidth - width)/2, (screenheight - height)/2) root.geometry(size) root.resizable(0, 0) lable = Label(root, height=2) lable['text'] = message lable.pack() entry = Entry(root) entry.bind('<Return>', return_callback) entry.pack() entry.focus_set() root.protocol("WM_DELETE_WINDOW", close_callback) root.mainloop() str = entry.get() root.destroy() return str
以上这篇Python弹出输入框并获取输入值的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
推荐阅读
-
Python 弹出输入框并获取输入值的示例
-
= 0; i--) {
printf("%5d", *(p + i));
}
printf("\n");
return 0;
}
```
2. 利用指针计算奇数索引数组元素之和
```c
// 使用指针计算奇数索引数组元素之和
#include
int main() { int arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9}; int n = sizeof(arr) / sizeof(arr[0]); printf("数组元素: "); for (int i = 0; i < n; i++) { printf("%3d", arr[i]); // 宽度为3,右对齐 } printf("\n"); printf("数组下标: "); for (int i = 0; i < n; i++) { printf("%3d", i); // 宽度为3,右对齐 } printf("\n"); int sum = 0; int *p = arr; // 声明指向整数的指针 for (int i = 0; i < n; i++) { if (i % 2 != 0) { sum += *(p + i); // 若索引i为奇数,累加对应元素值 } } printf("奇数索引数组元素之和: %d\n", sum); return 0; } ``` 3. 查看不同类型指针在Linux Ubuntu gcc下的字节大小 ```c // 在Linux Ubuntu gcc环境下查看不同类型指针的字节大小 #include #include int main() { printf("int指针大小: %zu bytes\n", sizeof(int *)); printf("char指针大小: %zu bytes\n", sizeof(char *)); printf("float指针大小: %zu bytes\n", sizeof(float *)); printf("double指针大小: %zu bytes\n", sizeof(double *)); return 0; } ``` 请注意,对于现代64位系统(如Linux),`int`、`char`、`float`和`double`指针通常都是8字节。但在某些特定情况下(如32位系统或特定编译环境),可能有所不同。 4. 使用指针遍历并打印字符数组 ```c // 使用指针遍历并打印字符数组 #include #include // 引入strlen函数 int main() { char str[] = "Hello, World"; // 字符串常量 int len = strlen(str); // 获取字符串长度 char *ptr = str; // 定义指向字符的指针 printf("输出字符串: %s\n", str); // 输出原始字符串 printf("遍历并打印字符数组: "); for (int i = 0; i < len; i++) { printf("%c", *ptr); // 输出当前字符 ptr++; // 移动指针到下一个字符 } printf("\n"); return 0; } ``` 对于用户自定义输入字符串的情况,请参考以下代码: ```c #include #include int main() { char input[100]; // 用于存放用户输入的字符串,假设最大长度为100 printf("请输入字符串: "); fgets(input, sizeof(input), stdin); // 从标准输入读取字符串,fgets会保留换行符 int len = strlen(input) - 1; // 去掉fgets读取的换行符 char *ptr = input; // 定义指向字符的指针 printf("输入的字符串: %s\n", input); printf("遍历并打印字符数组: "); for (int i = 0; i < len; i++) { printf("%c", *ptr); // 输出当前字符 ptr++; // 移动指针到下一个字符 } printf("\n"); return 0; } ```"> 1. 使用指针倒序显示整数数组内容 ```c // 通过指针逆序打印整数数组 #include
#include #include int main() { int arr[10] = {0}; int n = sizeof(arr) / sizeof(arr[0]); srand(time(NULL)); printf("原始数组: "); for (int i = 0; i < n; i++) { arr[i] = rand() % 100; printf("%5d", arr[i]); } printf("\n"); int *p = arr; // 指针指向数组元素 printf("反转打印数组元素: "); for (int i = n - 1; i >= 0; i--) { printf("%5d", *(p + i)); } printf("\n"); return 0; } ``` 2. 利用指针计算奇数索引数组元素之和 ```c // 使用指针计算奇数索引数组元素之和 #include int main() { int arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9}; int n = sizeof(arr) / sizeof(arr[0]); printf("数组元素: "); for (int i = 0; i < n; i++) { printf("%3d", arr[i]); // 宽度为3,右对齐 } printf("\n"); printf("数组下标: "); for (int i = 0; i < n; i++) { printf("%3d", i); // 宽度为3,右对齐 } printf("\n"); int sum = 0; int *p = arr; // 声明指向整数的指针 for (int i = 0; i < n; i++) { if (i % 2 != 0) { sum += *(p + i); // 若索引i为奇数,累加对应元素值 } } printf("奇数索引数组元素之和: %d\n", sum); return 0; } ``` 3. 查看不同类型指针在Linux Ubuntu gcc下的字节大小 ```c // 在Linux Ubuntu gcc环境下查看不同类型指针的字节大小 #include #include int main() { printf("int指针大小: %zu bytes\n", sizeof(int *)); printf("char指针大小: %zu bytes\n", sizeof(char *)); printf("float指针大小: %zu bytes\n", sizeof(float *)); printf("double指针大小: %zu bytes\n", sizeof(double *)); return 0; } ``` 请注意,对于现代64位系统(如Linux),`int`、`char`、`float`和`double`指针通常都是8字节。但在某些特定情况下(如32位系统或特定编译环境),可能有所不同。 4. 使用指针遍历并打印字符数组 ```c // 使用指针遍历并打印字符数组 #include #include // 引入strlen函数 int main() { char str[] = "Hello, World"; // 字符串常量 int len = strlen(str); // 获取字符串长度 char *ptr = str; // 定义指向字符的指针 printf("输出字符串: %s\n", str); // 输出原始字符串 printf("遍历并打印字符数组: "); for (int i = 0; i < len; i++) { printf("%c", *ptr); // 输出当前字符 ptr++; // 移动指针到下一个字符 } printf("\n"); return 0; } ``` 对于用户自定义输入字符串的情况,请参考以下代码: ```c #include #include int main() { char input[100]; // 用于存放用户输入的字符串,假设最大长度为100 printf("请输入字符串: "); fgets(input, sizeof(input), stdin); // 从标准输入读取字符串,fgets会保留换行符 int len = strlen(input) - 1; // 去掉fgets读取的换行符 char *ptr = input; // 定义指向字符的指针 printf("输入的字符串: %s\n", input); printf("遍历并打印字符数组: "); for (int i = 0; i < len; i++) { printf("%c", *ptr); // 输出当前字符 ptr++; // 移动指针到下一个字符 } printf("\n"); return 0; } ``` -
回顾2015年的HPV病毒基因研究:205种类型的发现,通过Python抓取获取了179个约8KB碱基序列。基于GeneBank或类似ID的批量核酸序列下载实用脚本" 该脚本说明: - 介绍了一个在2015年针对HPV病毒基因进行的研究,其中已确认有205种类型的基因,并通过Python编程从GeneBank获取了179个大约8KB的DNA序列片段。 - 提供了一份简单易用的Python脚本,用户只需提供一行一个含有相关ID(如GeneBank ID)的文本文件作为输入。 - 脚本功能包括随机暂停以避免过于频繁的请求,适用于快速、大批量地下载指定ID下的核酸序列信息。 - 还提及了关于HBV病毒提取方法的相关文献背景,同时也揭示了当年作者使用Python编写此类工具的经历。
-
南邮OJ Web任务大揭秘:层层挑战剖析 1. 挑战一:迷宫般的目录探索 题目作者似乎穷举了所有可能的目录组合,最终在404.php中的