【内部资料】python逐步打字文案效果
作者:野牛程序员:2023-11-10 16:14:54python阅读 2560
import tkinter as tk import time import keyword def simulate_typing(): code = [ "", "生命途中,", "胸怀豁达如蓝天,心若沉湖便是地狄。", "", "心之所系,即成心之所累;", "", "纠缠于何,即为何所纠缠。", "世事无常,顺其自然,", "天命难改,不过尔尔。", "痛苦之源,源自深沉执念,", "迷茫之根,根植于过度计较。", "期望过高,苦不堪言,舍去繁杂。", "非为原谅他人,", "唯愿轻装前行,放过己身。", "", ] window = tk.Tk() window.title("c语言1+1/1!+1/2!+1/3!......求和") window.configure(bg='#b7cb83') # 设置窗口背景色为黑色 # 获取屏幕宽度和高度 screen_width = window.winfo_screenwidth() screen_height = window.winfo_screenheight() # 设置窗口在屏幕中央 window_width = 360 window_height = 640 x_position = (screen_width - window_width) // 2 y_position = (screen_height - window_height) // 2 window.geometry(f"{window_width}x{window_height}+{x_position}+{y_position}") code_text = tk.Text(window, wrap=tk.WORD, width=40, height=40, font=("思源黑体", 14), fg='white', bg='#001f50') code_text.pack(padx=10, pady=10) for line in code: for char in line: code_text.insert(tk.END, char) code_text.update() time.sleep(0.1) # 控制每个字符的显示时间 code_text.insert(tk.END, '\\n') code_text.update() time.sleep(0.3) # 控制每行之间的间隔 # 设置关键字颜色 code_text.tag_configure('keyword', foreground='blue') window.mainloop() # 调用函数模拟逐字符显示效果 simulate_typing()
import tkinter as tk import time import keyword def simulate_typing(): code = [ "", "", "c++统计字符串中字母个数", "#include <iostream>", "#include <cctype>", "using namespace std;", "int main() {", " char inputString[100];", " // 输入字符串", " cout << \\"请输入一个字符串: \\";", " cin.getline(inputString, sizeof(inputString));", " int letterCount = 0;", " // 遍历字符串并统计字母个数", " for (int i = 0; inputString[i] != '\\\\0'; ++i) {", " if (isalpha(inputString[i])) {", " letterCount++;", " }", " }", " // 输出结果", " cout << \\"字符串中字母个数为: \\" << letterCount << endl;", " return 0;", "}" ] window = tk.Tk() window.title("c语言1+1/1!+1/2!+1/3!......求和") window.configure(bg='black') # 设置窗口背景色为黑色 # 获取屏幕宽度和高度 screen_width = window.winfo_screenwidth() screen_height = window.winfo_screenheight() # 设置窗口在屏幕中央 window_width = 360 window_height = 640 x_position = (screen_width - window_width) // 2 y_position = (screen_height - window_height) // 2 window.geometry(f"{window_width}x{window_height}+{x_position}+{y_position}") code_text = tk.Text(window, wrap=tk.WORD, width=40, height=40, font=("思源黑体", 13), fg='white', bg='black') code_text.pack(padx=10, pady=10) for line in code: for char in line: code_text.insert(tk.END, char) code_text.update() time.sleep(0.1) # 控制每个字符的显示时间 code_text.insert(tk.END, '\\n') code_text.update() time.sleep(0.3) # 控制每行之间的间隔 # 设置关键字颜色 code_text.tag_configure('keyword', foreground='blue') window.mainloop() # 调用函数模拟逐字符显示效果 simulate_typing()
野牛程序员教少儿编程与信息学奥赛-微信|电话:15892516892