error C2275 : 'UNICODE_STRING' :illegal use of this type as an expression

本文探讨了一个在C语言驱动开发中遇到的问题,即如何正确地使用UNICODE_STRING类型。文中给出了一段具体的代码示例,并指出了一个常见的错误用法及相应的修正方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

真是个神奇的错误 :

我的代码是这样的:

#define MYDEVICE_DOS_DEVICE_NAME_W L"\\DosDevices\\myDevice"

//卸载设备
void Unload(IN PDRIVER_OBJECT pDriverObject)
{
KdPrint((" Unload Begin\n"));

//要先删除符号连接
UNICODE_STRING ustrDosDeviceName;
RtlInitUnicodeString(&ustrDosDeviceName, MYDEVICE_DOS_DEVICE_NAME_W);
IoDeleteSymbolicLink(&ustrDosDeviceName);
//再通过驱动对象删除设备对象
IoDeleteDevice(pDriverObject->DeviceObject);
KdPrint(("Unload End \n"));
}

按照C++的习惯,这是不会报错的,但因为公司要求驱动最好使用C语言编写,所以这时我就在阴沟里翻船了。

error C2275 : 'UNICODE_STRING' :illegal use of this type as an expression

必须要将这

UNICODE_STRING ustrDosDeviceName;

放入到函数体的首部,就不会报错了。

import tkinter as tk from tkinter import scrolledtext, ttk, messagebox import os import logging from datetime import datetime class SimpleCLexer: def __init__(self): self.tokens = [] def tokenize(self, input_str): tokens = [] pos = 0 line = 1 column = 0 length = len(input_str) # 定义C语言的关键词和类型 keywords = { 'void', 'int', 'char', 'float', 'double', 'short', 'long', 'signed', 'unsigned', 'struct', 'union', 'enum', 'typedef', 'static', 'extern', 'auto', 'register', 'const', 'volatile', 'return', 'if', 'else', 'switch', 'case', 'default', 'for', 'while', 'do', 'break', 'continue', 'goto', 'sizeof' } # 扩展类型别名识别 types = {'U1', 'U2', 'U4', 'S1', 'S2', 'S4', 'BOOL', 'BYTE', 'WORD', 'DWORD'} while pos < length: char = input_str[pos] # 跳过空白字符 if char in ' \t': pos += 1 column += 1 continue # 处理换行 if char == '\n': line += 1 column = 0 pos += 1 continue # 处理单行注释 if pos + 1 < length and input_str[pos:pos+2] == '//': end = input_str.find('\n', pos) if end == -1: end = length pos = end continue # 处理多行注释 if pos + 1 < length and input_str[pos:pos+2] == '/*': end = input_str.find('*/', pos + 2) if end == -1: end = length else: end += 2 pos = end continue # 处理标识符 if char.isalpha() or char == '_': start = pos pos += 1 while pos < length and (input_str[pos].isalnum() or input_str[pos] == '_'): pos += 1 token_text = input_str[start:pos] token_type = 'IDENTIFIER' # 检查是否为关键字或类型 if token_text in keywords: token_type = 'KEYWORD' elif token_text in types: token_type = 'TYPE' tokens.append({ 'type': token_type, 'text': token_text, 'line': line, 'column': column }) column += (pos - start) continue # 处理数字 if char.isdigit(): start = pos pos += 1 while pos < length and (input_str[pos].isdigit() or input_str[pos] in '.xXabcdefABCDEF'): pos += 1 tokens.append({ 'type': 'NUMBER', 'text': input_str[start:pos], 'line': line, 'column': column }) column += (pos - start) continue # 处理字符串 if char == '"': start = pos pos += 1 while pos < length and input_str[pos] != '"': if input_str[pos] == '\\' and pos + 1 < length: pos += 2 else: pos += 1 if pos < length and input_str[pos] == '"': pos += 1 tokens.append({ 'type': 'STRING', 'text': input_str[start:pos], 'line': line, 'column': column }) column += (pos - start) continue # 处理字符 if char == "'": start = pos pos += 1 while pos < length and input_str[pos] != "'": if input_str[pos] == '\\' and pos + 1 < length: pos += 2 else: pos += 1 if pos < length and input_str[pos] == "'": pos += 1 tokens.append({ 'type': 'CHAR', 'text': input_str[start:pos], 'line': line, 'column': column }) column += (pos - start) continue # 处理运算符和标点符号 operators = { '(', ')', '{', '}', '[', ']', ';', ',', '.', '->', '++', '--', '&', '*', '+', '-', '~', '!', '/', '%', '<<', '>>', '<', '>', '<=', '>=', '==', '!=', '^', '|', '&&', '||', '?', ':', '=', '+=', '-=', '*=', '/=', '%=', '<<=', '>>=', '&=', '^=', '|=', ',' } # 尝试匹配最长的运算符 matched = False for op_len in range(3, 0, -1): if pos + op_len <= length and input_str[pos:pos+op_len] in operators: tokens.append({ 'type': 'OPERATOR', 'text': input_str[pos:pos+op_len], 'line': line, 'column': column }) pos += op_len column += op_len matched = True break if matched: continue # 无法识别的字符 tokens.append({ 'type': 'UNKNOWN', 'text': char, 'line': line, 'column': column }) pos += 1 column += 1 return tokens class FunctionAnalyzer: def __init__(self): self.function_name = "" self.parameters = set() self.local_vars = [] self.global_vars = [] self.function_calls = [] self.current_function = None self.in_function = False self.in_function_body = False self.brace_depth = 0 self.variable_declarations = {} self.control_structures = {"if", "for", "while", "switch", "return", "else"} self.macro_definitions = set() self.recorded_globals = set() self.storage_classes = {"static", "extern", "auto", "register"} # 定义允许的类型(修复错误) self.basic_types = {'void', 'int', 'char', 'float', 'double', 'short', 'long', 'signed', 'unsigned'} self.type_aliases = {"U1", "U2", "U4", "S1", "S2", "S4"} self.allowed_types = self.basic_types | self.type_aliases self.inside_expression = False # 添加新状态跟踪 # 添加函数前缀识别 self.function_prefixes = { "vd_": "void", "u1_": "U1", "u2_": "U2", "u4_": "U4", "s1_": "S1", "s2_": "S2", "s4_": "S4" } def analyze(self, tokens): self.tokens = tokens self.pos = 0 self.current_line = 0 self.inside_expression = False # 重置表达式状态 # 第一步:识别宏定义(全大写标识符) self._identify_macros() # 第二步:分析函数体 while self.pos < len(self.tokens): token = self.tokens[self.pos] self.current_line = token['line'] # 检测表达式开始和结束 if token['text'] in {'(', '{', '['}: self.inside_expression = True elif token['text'] in {')', '}', ']'}: self.inside_expression = False # 检测函数定义 if token['text'] in self.storage_classes or token['text'] in self.allowed_types: if self._is_function_definition(): self._handle_function_definition() continue # 在函数体内检测变量声明 if self.in_function_body: if token['text'] in self.allowed_types: self._handle_variable_declaration() continue # 检测函数调用 if token['type'] == 'IDENTIFIER' and self.pos + 1 < len(self.tokens): next_token = self.tokens[self.pos + 1] if next_token['text'] == '(': self._handle_function_call() continue # 检测变量使用 if token['type'] == 'IDENTIFIER': self._handle_identifier_use(token) # 跟踪大括号深度 if token['text'] == '{': self.brace_depth += 1 if self.in_function and self.brace_depth == 1: self.in_function_body = True elif token['text'] == '}': self.brace_depth -= 1 if self.brace_depth == 0 and self.in_function: self.in_function = False self.in_function_body = False self.pos += 1 return self def _identify_macros(self): """识别宏定义(全大写标识符)""" for token in self.tokens: if token['type'] == 'IDENTIFIER' and token['text'].isupper(): self.macro_definitions.add(token['text']) def _is_function_definition(self): pos = self.pos storage_class = None # 检测存储类说明符 if self.tokens[pos]['text'] in self.storage_classes: storage_class = self.tokens[pos]['text'] pos += 1 # 检测返回类型 if pos >= len(self.tokens) or self.tokens[pos]['text'] not in self.allowed_types: return False return_type = self.tokens[pos]['text'] pos += 1 # 处理指针声明 if pos < len(self.tokens) and self.tokens[pos]['text'] == '*': return_type += '*' pos += 1 # 检测函数名 if pos < len(self.tokens) and self.tokens[pos]['type'] == 'IDENTIFIER': func_name = self.tokens[pos]['text'] pos += 1 else: return False # 检测参数列表开头的'(' if pos < len(self.tokens) and self.tokens[pos]['text'] == '(': pos += 1 else: return False # 参数列表必须包含至少一个参数或void if pos < len(self.tokens) and self.tokens[pos]['text'] == ')': # 空参数列表 pos += 1 else: # 非空参数列表 depth = 1 while pos < len(self.tokens) and depth > 0: if self.tokens[pos]['text'] == '(': depth += 1 elif self.tokens[pos]['text'] == ')': depth -= 1 pos += 1 # 检测函数体开头的'{' (允许最多5个token的间隔) found_brace = False for i in range(min(5, len(self.tokens) - pos)): if self.tokens[pos + i]['text'] == '{': found_brace = True break return found_brace def _handle_function_definition(self): start_pos = self.pos storage_class = None # 处理存储类说明符 if self.tokens[self.pos]['text'] in self.storage_classes: storage_class = self.tokens[self.pos]['text'] self.pos += 1 # 获取返回类型 return_type = self.tokens[self.pos]['text'] self.pos += 1 # 处理指针声明 if self.pos < len(self.tokens) and self.tokens[self.pos]['text'] == '*': return_type += '*' self.pos += 1 # 获取函数名 if self.pos < len(self.tokens) and self.tokens[self.pos]['type'] == 'IDENTIFIER': func_name = self.tokens[self.pos]['text'] self.pos += 1 else: self.pos = start_pos return # 记录函数名 self.function_name = func_name self.current_function = func_name self.variable_declarations[func_name] = True # 跳过 '(' if self.pos < len(self.tokens) and self.tokens[self.pos]['text'] == '(': self.pos += 1 # 提取参数 params = [] current_param = [] depth = 1 param_line = self.current_line while self.pos < len(self.tokens) and depth > 0: token = self.tokens[self.pos] if token['text'] == '(': depth += 1 elif token['text'] == ')': depth -= 1 if depth == 0: break elif token['text'] == ',' and depth == 1: # 提取参数类型和名称 param_type, param_name = self._extract_param_info(current_param) if param_type and param_name: params.append({ 'type': param_type, 'name': param_name, 'line': param_line }) self.variable_declarations[param_name] = True current_param = [] param_line = token['line'] self.pos += 1 continue current_param.append(token) self.pos += 1 # 处理最后一个参数 if current_param: param_type, param_name = self._extract_param_info(current_param) if param_type and param_name: params.append({ 'type': param_type, 'name': param_name, 'line': param_line }) self.variable_declarations[param_name] = True # 记录参数 self.parameters = params param_names = [p['name'] for p in params] if params else [] # 查找函数体开头的'{' while self.pos < len(self.tokens) and self.tokens[self.pos]['text'] != '{': self.pos += 1 if self.pos < len(self.tokens) and self.tokens[self.pos]['text'] == '{': self.in_function = True self.in_function_body = False self.brace_depth = 0 self.pos += 1 return param_names def _extract_param_info(self, tokens): """从参数token列表中提取类型和名称""" param_type = [] param_name = None for token in tokens: if token['type'] in ('KEYWORD', 'TYPE') or token['text'] in self.allowed_types: param_type.append(token['text']) elif token['type'] == 'IDENTIFIER' and not token['text'].isupper(): param_name = token['text'] return ' '.join(param_type), param_name def _handle_variable_declaration(self): # 获取变量类型 var_type = self.tokens[self.pos]['text'] self.log(f"检测到变量声明类型: {var_type}", "debug") self.pos += 1 # 处理指针声明 if self.pos < len(self.tokens) and self.tokens[self.pos]['text'] == '*': var_type += '*' self.pos += 1 var_names = [] current_line = self.current_line # 处理变量名 while self.pos < len(self.tokens): token = self.tokens[self.pos] # 标识符 - 变量名 if token['type'] == 'IDENTIFIER' and not token['text'].isupper(): var_name = token['text'] # 跳过宏定义 if var_name not in self.macro_definitions: self.log(f"找到变量名: {var_name}", "debug") var_names.append(var_name) self.variable_declarations[var_name] = True self.pos += 1 continue # 逗号 - 多个变量声明 elif token['text'] == ',': self.pos += 1 # 处理指针声明 if self.pos < len(self.tokens) and self.tokens[self.pos]['text'] == '*': self.pos += 1 continue # 结束声明 elif token['text'] == ';': self.pos += 1 break # 数组声明 - 跳过数组大小 elif token['text'] == '[': self.pos += 1 depth = 1 while self.pos < len(self.tokens) and depth > 0: t = self.tokens[self.pos] if t['text'] == '[': depth += 1 elif t['text'] == ']': depth -= 1 self.pos += 1 continue # 初始化 - 跳过初始化表达式 elif token['text'] == '=': self.log("跳过初始化表达式", "debug") self.pos += 1 depth = 0 while self.pos < len(self.tokens): t = self.tokens[self.pos] if t['text'] in {'(', '['}: depth += 1 elif t['text'] in {')', ']'}: depth -= 1 elif t['text'] in {',', ';'} and depth == 0: break self.pos += 1 continue # 类型转换 - 跳过 elif token['text'] == '(' and self.pos + 1 < len(self.tokens): # 尝试识别类型转换 next_token = self.tokens[self.pos + 1] if next_token['text'] in self.allowed_types: self.log(f"跳过类型转换: ({next_token['text']})", "debug") # 跳过类型转换 self.pos += 2 if self.pos < len(self.tokens) and self.tokens[self.pos]['text'] == ')': self.pos += 1 continue # 其他情况 self.log(f"跳过token: {token['text']} (类型: {token['type']})", "debug") self.pos += 1 # 添加到局部变量 (跳过宏定义和参数) for var_name in var_names: # 检查是否在参数列表中 is_param = False for param in self.parameters: if param['name'] == var_name: is_param = True self.log(f"跳过参数变量: {var_name}", "debug") break if not is_param and var_name not in self.macro_definitions: self.local_vars.append({ 'type': var_type, 'name': var_name, 'line': current_line }) self.log(f"添加局部变量: {var_type} {var_name}", "info") def _handle_identifier_use(self, token): var_name = token['text'] line = token['line'] # 跳过宏定义(全大写) if var_name in self.macro_definitions or var_name.isupper(): self.log(f"跳过宏定义: {var_name}", "debug") return # 跳过已声明的变量(局部变量、参数、函数名) if var_name in self.variable_declarations: self.log(f"跳过已声明变量: {var_name}", "debug") return # 跳过函数调用(函数名已经在函数调用处理中记录) for call in self.function_calls: if call['name'] == var_name: self.log(f"跳过函数调用变量: {var_name}", "debug") return # 跳过控制结构 if var_name in self.control_structures: self.log(f"跳过控制结构: {var_name}", "debug") return # 跳过类型别名 if var_name in self.type_aliases: self.log(f"跳过类型别名: {var_name}", "debug") return # 跳过已经记录过的全局变量 if var_name in self.recorded_globals: self.log(f"跳过已记录全局变量: {var_name}", "debug") return # 添加到全局变量 self.global_vars.append({ 'name': var_name, 'line': line }) self.recorded_globals.add(var_name) self.log(f"添加全局变量: {var_name}", "info") def log(self, message, level="info"): """添加内部日志方法""" # 在实际应用中,这个方法应该连接到GUI日志系统 print(f"[Analyzer] {level.upper()}: {message}") # 在生产环境中,应该调用GUI的日志方法 # self.log_to_gui(f"[Analyzer] {message}", level) def _handle_function_call(self): # 提取函数名 func_name = self.tokens[self.pos]['text'] line = self.current_line self.pos += 2 # 跳过函数名和 '(' # 提取参数 params = [] depth = 1 current_param = [] while self.pos < len(self.tokens) and depth > 0: token = self.tokens[self.pos] if token['text'] == '(': depth += 1 elif token['text'] == ')': depth -= 1 if depth == 0: break elif token['text'] == ',' and depth == 1: params.append(''.join([t['text'] for t in current_param]).strip()) current_param = [] self.pos += 1 continue current_param.append(token) self.pos += 1 if current_param: params.append(''.join([t['text'] for t in current_param]).strip()) # 跳过 ')' 如果还在范围内 if self.pos < len(self.tokens) and self.tokens[self.pos]['text'] == ')': self.pos += 1 # 确定返回类型 return_type = "unknown" if func_name.startswith("vd_"): return_type = "void" elif func_name.startswith(("u1_", "u2_", "u4_", "s1_", "s2_", "s4_")): prefix = func_name.split("_")[0] return_type = prefix.upper() # 添加到函数调用列表 self.function_calls.append({ 'name': func_name, 'return_type': return_type, 'type': "function", 'params': ", ".join(params), 'line': line }) class FunctionParserApp: def __init__(self, root): self.root = root self.root.title("C语言函数解析器 (内置解析器版)") self.root.geometry("900x700") self.setup_logging() # 创建输入区域 input_frame = tk.LabelFrame(root, text="输入C语言函数体", padx=5, pady=5) input_frame.pack(fill="both", expand=True, padx=10, pady=5) self.input_text = scrolledtext.ScrolledText(input_frame, width=100, height=20) self.input_text.pack(fill="both", expand=True, padx=5, pady=5) # 按钮区域 btn_frame = tk.Frame(root) btn_frame.pack(fill="x", padx=10, pady=5) # 解析按钮 parse_btn = tk.Button(btn_frame, text="解析函数", command=self.parse_function, bg="#4CAF50", fg="white") parse_btn.pack(side="left", padx=5) # 保存日志按钮 save_log_btn = tk.Button(btn_frame, text="保存日志", command=self.save_logs) save_log_btn.pack(side="right", padx=5) # 进度条 self.progress = ttk.Progressbar(btn_frame, orient="horizontal", length=300, mode="determinate") self.progress.pack(side="left", padx=10, fill="x", expand=True) # 创建输出区域 output_frame = tk.LabelFrame(root, text="解析结果", padx=5, pady=5) output_frame.pack(fill="both", expand=True, padx=10, pady=5) self.output_text = scrolledtext.ScrolledText(output_frame, width=100, height=15) self.output_text.pack(fill="both", expand=True, padx=5, pady=5) self.output_text.config(state=tk.DISABLED) # 日志区域 log_frame = tk.LabelFrame(root, text="日志信息", padx=5, pady=5) log_frame.pack(fill="both", expand=True, padx=10, pady=5) self.log_text = scrolledtext.ScrolledText(log_frame, width=100, height=8) self.log_text.pack(fill="both", expand=True, padx=5, pady=5) self.log_text.config(state=tk.DISABLED) # 添加示例按钮 example_btn = tk.Button(btn_frame, text="加载示例", command=self.load_example) example_btn.pack(side="right", padx=5) # 示例函数体 self.example_code = """static void Diag21_PID_C9(U1 u1_a_num) { U1 u1_t_cmplt; U1 u1_t_cnt; if((U1)DIAG_CNT_ZERO == u1_t_swrstcnt) /* Determine if a software reset is in progress */ { for(u1_t_cnt = (U1)DIAG21_ZERO; u1_t_cnt < (U1)DIAG21_PIDC9_FLAG; u1_t_cnt ++) { u1_t_cmplt = u1_g_InspSoftwareVersion(u4_g_cmd, &u4_g_data, (U1)TRUE); } vd_s_Diag21_U2ToU1(u2_g_buf, u1_g_data, (U1)DIAG21_PIDC9_FLAG); } else { /* Do Nothing */ } }""" def setup_logging(self): """配置日志系统""" self.log_filename = f"parser_{datetime.now().strftime('%Y%m%d_%H%M%S')}.log" logging.basicConfig( filename=self.log_filename, level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s" ) logging.info("应用程序启动") def log_to_gui(self, message, level="info"): """将日志信息显示在GUI中""" self.log_text.config(state=tk.NORMAL) timestamp = datetime.now().strftime("%H:%M:%S") self.log_text.insert(tk.END, f"[{timestamp}] {message}\n") self.log_text.see(tk.END) self.log_text.config(state=tk.DISABLED) if level == "info": logging.info(message) elif level == "warning": logging.warning(message) elif level == "error": logging.error(message) def save_logs(self): """保存日志到文件""" try: log_content = self.log_text.get("1.0", tk.END) filename = f"saved_log_{datetime.now().strftime('%H%M%S')}.txt" with open(filename, "w") as f: f.write(log_content) self.log_to_gui(f"日志已保存到: {filename}", "info") messagebox.showinfo("保存成功", f"日志已保存到:\n{filename}") except Exception as e: self.log_to_gui(f"保存日志失败: {str(e)}", "error") messagebox.showerror("保存失败", f"无法保存日志:\n{str(e)}") def update_progress(self, value): """更新进度条""" self.progress['value'] = value self.root.update_idletasks() def load_example(self): """加载示例函数体""" self.input_text.delete(1.0, tk.END) self.input_text.insert(tk.END, self.example_code) self.log_to_gui("已加载示例函数体") def parse_function(self): """使用内置解析器解析C语言函数体""" try: code = self.input_text.get(1.0, tk.END) if not code.strip(): self.log_to_gui("错误: 没有输入函数体", "error") messagebox.showerror("错误", "请输入要解析的C语言函数体") return self.log_to_gui("开始解析函数体...") self.output_text.config(state=tk.NORMAL) self.output_text.delete(1.0, tk.END) self.update_progress(0) # 使用内置词法分析器 self.log_to_gui("执行词法分析...") lexer = SimpleCLexer() tokens = lexer.tokenize(code) self.update_progress(30) # 使用内置语法分析器 self.log_to_gui("执行语法分析...") analyzer = FunctionAnalyzer() analyzer.log_to_gui = self.log_to_gui # 连接日志系统 analyzer.analyze(tokens) self.update_progress(70) # 显示结果 self.log_to_gui("生成解析报告...") self.display_results( analyzer.local_vars, analyzer.global_vars, analyzer.function_calls, analyzer.function_name, analyzer.parameters ) self.update_progress(100) self.output_text.config(state=tk.DISABLED) self.log_to_gui("解析完成!") messagebox.showinfo("完成", "函数体解析成功完成!") except Exception as e: self.log_to_gui(f"解析错误: {str(e)}", "error") self.log_to_gui(f"错误详情: {traceback.format_exc()}", "error") messagebox.showerror("解析错误", f"发生错误:\n{str(e)}") self.update_progress(0) def display_results(self, local_vars, global_vars, function_calls, func_name, func_params): """显示解析结果""" # 显示函数签名 if func_name: self.output_text.insert(tk.END, "=== 函数签名 ===\n") self.output_text.insert(tk.END, f"函数名: {func_name}\n") # 修复参数显示问题 if func_params: param_list = [] for param in func_params: param_list.append(f"{param['type']} {param['name']}") self.output_text.insert(tk.END, f"参数: {', '.join(param_list)}\n\n") else: self.output_text.insert(tk.END, "参数: 无\n\n") else: self.output_text.insert(tk.END, "=== 函数签名 ===\n") self.output_text.insert(tk.END, "警告: 无法识别函数签名\n\n") self.log_to_gui("无法识别函数签名", "warning") # 显示局部变量 if local_vars: self.output_text.insert(tk.END, "=== 局部变量 ===\n") for var in local_vars: self.output_text.insert(tk.END, f"{var['type']} {var['name']} (行号: {var['line']})\n") self.log_to_gui(f"找到局部变量: {var['type']} {var['name']}") self.output_text.insert(tk.END, "\n") else: self.output_text.insert(tk.END, "未找到局部变量\n\n") self.log_to_gui("未找到局部变量", "warning") # 显示使用的全局变量 if global_vars: self.output_text.insert(tk.END, "=== 使用的全局变量 ===\n") for var in global_vars: self.output_text.insert(tk.END, f"{var['name']} (行号: {var['line']})\n") self.log_to_gui(f"找到全局变量: {var['name']}") self.output_text.insert(tk.END, "\n") else: self.output_text.insert(tk.END, "未使用全局变量\n\n") self.log_to_gui("未使用全局变量", "warning") # 显示函数调用 if function_calls: self.output_text.insert(tk.END, "=== 函数调用 ===\n") for func in function_calls: self.output_text.insert(tk.END, f"函数名: {func['name']} (行号: {func['line']})\n") self.output_text.insert(tk.END, f"返回类型: {func['return_type']}\n") self.output_text.insert(tk.END, f"参数: {func['params']}\n") self.output_text.insert(tk.END, "-" * 50 + "\n") self.log_to_gui(f"找到函数调用: {func['name']}") else: self.output_text.insert(tk.END, "未调用任何函数\n\n") self.log_to_gui("未调用任何函数", "warning") # 显示统计信息 self.output_text.insert(tk.END, "=== 解析统计 ===\n") self.output_text.insert(tk.END, f"局部变量数量: {len(local_vars)}\n") self.output_text.insert(tk.END, f"使用的全局变量数量: {len(global_vars)}\n") self.output_text.insert(tk.END, f"函数调用数量: {len(function_calls)}\n") self.output_text.insert(tk.END, "\n") if __name__ == "__main__": root = tk.Tk() app = FunctionParserApp(root) root.mainloop() [11:41:52] 已加载示例函数体 [11:41:53] 开始解析函数体... [11:41:53] 执行词法分析... [11:41:53] 执行语法分析... [11:41:53] 解析错误: 'cp932' codec can't encode character '\u53d8' in position 21: illegal multibyte sequence
07-18
--- Logging error --- Traceback (most recent call last): File "D:\Anaconda\Lib\logging\__init__.py", line 1163, in emit stream.write(msg + self.terminator) UnicodeEncodeError: 'gbk' codec can't encode character '\xb3' in position 75: illegal multibyte sequence Call stack: File "D:\PythonProject1\水位计算软件.py", line 606, in <module> root.mainloop() File "D:\Anaconda\Lib\tkinter\__init__.py", line 1505, in mainloop self.tk.mainloop(n) File "D:\Anaconda\Lib\tkinter\__init__.py", line 1968, in __call__ return self.func(*args) File "D:\PythonProject1\水位计算软件.py", line 572, in show_results self.calculator.plot_results() File "D:\PythonProject1\水位计算软件.py", line 274, in plot_results plt.show() File "D:\Anaconda\Lib\site-packages\matplotlib\pyplot.py", line 614, in show return _get_backend_mod().show(*args, **kwargs) File "D:\Anaconda\Lib\site-packages\matplotlib\backend_bases.py", line 3547, in show cls.mainloop() File "D:\Anaconda\Lib\site-packages\matplotlib\backends\_backend_tk.py", line 544, in start_main_loop first_manager.window.mainloop() File "D:\Anaconda\Lib\tkinter\__init__.py", line 1505, in mainloop self.tk.mainloop(n) File "D:\Anaconda\Lib\tkinter\__init__.py", line 1968, in __call__ return self.func(*args) File "D:\Anaconda\Lib\tkinter\__init__.py", line 862, in callit func(*args) File "D:\Anaconda\Lib\site-packages\matplotlib\backends\_backend_tk.py", line 274, in idle_draw self.draw() File "D:\Anaconda\Lib\site-packages\matplotlib\backends\backend_tkagg.py", line 10, in draw super().draw() File "D:\Anaconda\Lib\site-packages\matplotlib\backends\backend_agg.py", line 382, in draw self.figure.draw(self.renderer) File "D:\Anaconda\Lib\site-packages\matplotlib\artist.py", line 94, in draw_wrapper result = draw(artist, renderer, *args, **kwargs) File "D:\Anaconda\Lib\site-packages\matplotlib\artist.py", line 71, in draw_wrapper return draw(artist, renderer) File "D:\Anaconda\Lib\site-packages\matplotlib\figure.py", line 3257, in draw mimage._draw_list_compositing_images( File "D:\Anaconda\Lib\site-packages\matplotlib\image.py", line 134, in _draw_list_compositing_images a.draw(renderer) File "D:\Anaconda\Lib\site-packages\matplotlib\artist.py", line 71, in draw_wrapper return draw(artist, renderer) File "D:\Anaconda\Lib\site-packages\matplotlib\axes\_base.py", line 3181, in draw mimage._draw_list_compositing_images( File "D:\Anaconda\Lib\site-packages\matplotlib\image.py", line 134, in _draw_list_compositing_images a.draw(renderer) File "D:\Anaconda\Lib\site-packages\matplotlib\artist.py", line 71, in draw_wrapper return draw(artist, renderer) File "D:\Anaconda\Lib\site-packages\matplotlib\axis.py", line 1423, in draw self.label.draw(renderer) File "D:\Anaconda\Lib\site-packages\matplotlib\artist.py", line 71, in draw_wrapper return draw(artist, renderer) File "D:\Anaconda\Lib\site-packages\matplotlib\text.py", line 752, in draw bbox, info, descent = self._get_layout(renderer) File "D:\Anaconda\Lib\site-packages\matplotlib\text.py", line 382, in _get_layout w, h, d = _get_text_metrics_with_cache( File "D:\Anaconda\Lib\site-packages\matplotlib\text.py", line 69, in _get_text_metrics_with_cache return _get_text_metrics_with_cache_impl( File "D:\Anaconda\Lib\site-packages\matplotlib\text.py", line 77, in _get_text_metrics_with_cache_impl return renderer_ref().get_text_width_height_descent(text, fontprop, ismath) File "D:\Anaconda\Lib\site-packages\matplotlib\backends\backend_agg.py", line 215, in get_text_width_height_descent self.mathtext_parser.parse(s, self.dpi, prop) File "D:\Anaconda\Lib\site-packages\matplotlib\mathtext.py", line 86, in parse return self._parse_cached(s, dpi, prop, antialiased, load_glyph_flags) File "D:\Anaconda\Lib\site-packages\matplotlib\mathtext.py", line 100, in _parse_cached box = self._parser.parse(s, fontset, fontsize, dpi) File "D:\Anaconda\Lib\site-packages\matplotlib\_mathtext.py", line 2170, in parse result = self._expression.parseString(s) File "D:\Anaconda\Lib\site-packages\pyparsing\core.py", line 1131, in parse_string loc, tokens = self._parse(instring, 0) File "D:\Anaconda\Lib\site-packages\pyparsing\core.py", line 921, in _parseCache value = self._parseNoCache(instring, loc, doActions, callPreParse) File "D:\Anaconda\Lib\site-packages\pyparsing\core.py", line 817, in _parseNoCache loc, tokens = self.parseImpl(instring, pre_loc, doActions) File "D:\Anaconda\Lib\site-packages\pyparsing\core.py", line 3886, in parseImpl loc, exprtokens = e._parse(instring, loc, doActions) File "D:\Anaconda\Lib\site-packages\pyparsing\core.py", line 921, in _parseCache value = self._parseNoCache(instring, loc, doActions, callPreParse) File "D:\Anaconda\Lib\site-packages\pyparsing\core.py", line 817, in _parseNoCache loc, tokens = self.parseImpl(instring, pre_loc, doActions) File "D:\Anaconda\Lib\site-packages\pyparsing\core.py", line 4891, in parseImpl return super().parseImpl(instring, loc, doActions) File "D:\Anaconda\Lib\site-packages\pyparsing\core.py", line 4790, in parseImpl loc, tokens = self_expr_parse(instring, loc, doActions) File "D:\Anaconda\Lib\site-packages\pyparsing\core.py", line 921, in _parseCache value = self._parseNoCache(instring, loc, doActions, callPreParse) File "D:\Anaconda\Lib\site-packages\pyparsing\core.py", line 817, in _parseNoCache loc, tokens = self.parseImpl(instring, pre_loc, doActions) File "D:\Anaconda\Lib\site-packages\pyparsing\core.py", line 3886, in parseImpl loc, exprtokens = e._parse(instring, loc, doActions) File "D:\Anaconda\Lib\site-packages\pyparsing\core.py", line 921, in _parseCache value = self._parseNoCache(instring, loc, doActions, callPreParse) File "D:\Anaconda\Lib\site-packages\pyparsing\core.py", line 856, in _parseNoCache tokens = fn(instring, tokens_start, ret_tokens) File "D:\Anaconda\Lib\site-packages\pyparsing\core.py", line 291, in wrapper ret = func(*args[limit:]) File "D:\Anaconda\Lib\site-packages\matplotlib\_mathtext.py", line 2206, in non_math symbols = [Char(c, self.get_state()) for c in s] File "D:\Anaconda\Lib\site-packages\matplotlib\_mathtext.py", line 1091, in __init__ self._update_metrics() File "D:\Anaconda\Lib\site-packages\matplotlib\_mathtext.py", line 1097, in _update_metrics metrics = self._metrics = self.fontset.get_metrics( File "D:\Anaconda\Lib\site-packages\matplotlib\_mathtext.py", line 286, in get_metrics info = self._get_info(font, font_class, sym, fontsize, dpi) File "D:\Anaconda\Lib\site-packages\matplotlib\_mathtext.py", line 375, in _get_info font, num, slanted = self._get_glyph(fontname, font_class, sym) File "D:\Anaconda\Lib\site-packages\matplotlib\_mathtext.py", line 710, in _get_glyph return super()._get_glyph(fontname, font_class, sym) File "D:\Anaconda\Lib\site-packages\matplotlib\_mathtext.py", line 648, in _get_glyph _log.info("Substituting symbol %s from %s", sym, family) Message: 'Substituting symbol %s from %s' Arguments: ('³', 'STIXGeneral') 2025-07-26 16:29:36,050 - matplotlib.mathtext - WARNING - Font 'default' does not have a glyph for '\xb3' [U+b3], substituting with a dummy symbol. 2025-07-26 16:29:36,051 - matplotlib.mathtext - INFO - Substituting symbol ³ from STIXGeneral 2025-07-26 16:29:36,145 - matplotlib.mathtext - WARNING - Font 'default' does not have a glyph for '\xb3' [U+b3], substituting with a dummy symbol. 2025-07-26 16:29:36,145 - matplotlib.mathtext - INFO - Substituting symbol ³ from STIXGeneral --- Logging error --- Traceback (most recent call last): File "D:\Anaconda\Lib\logging\__init__.py", line 1163, in emit stream.write(msg + self.terminator) UnicodeEncodeError: 'gbk' codec can't encode character '\xb3' in position 75: illegal multibyte sequence Call stack: File "D:\PythonProject1\水位计算软件.py", line 606, in <module> root.mainloop() File "D:\Anaconda\Lib\tkinter\__init__.py", line 1505, in mainloop self.tk.mainloop(n) File "D:\Anaconda\Lib\tkinter\__init__.py", line 1968, in __call__ return self.func(*args) File "D:\PythonProject1\水位计算软件.py", line 572, in show_results self.calculator.plot_results() File "D:\PythonProject1\水位计算软件.py", line 274, in plot_results plt.show() File "D:\Anaconda\Lib\site-packages\matplotlib\pyplot.py", line 614, in show return _get_backend_mod().show(*args, **kwargs) File "D:\Anaconda\Lib\site-packages\matplotlib\backend_bases.py", line 3547, in show cls.mainloop() File "D:\Anaconda\Lib\site-packages\matplotlib\backends\_backend_tk.py", line 544, in start_main_loop first_manager.window.mainloop() File "D:\Anaconda\Lib\tkinter\__init__.py", line 1505, in mainloop self.tk.mainloop(n) File "D:\Anaconda\Lib\tkinter\__init__.py", line 1968, in __call__ return self.func(*args) File "D:\Anaconda\Lib\tkinter\__init__.py", line 862, in callit func(*args) File "D:\Anaconda\Lib\site-packages\matplotlib\backends\_backend_tk.py", line 274, in idle_draw self.draw() File "D:\Anaconda\Lib\site-packages\matplotlib\backends\backend_tkagg.py", line 10, in draw super().draw() File "D:\Anaconda\Lib\site-packages\matplotlib\backends\backend_agg.py", line 382, in draw self.figure.draw(self.renderer) File "D:\Anaconda\Lib\site-packages\matplotlib\artist.py", line 94, in draw_wrapper result = draw(artist, renderer, *args, **kwargs) File "D:\Anaconda\Lib\site-packages\matplotlib\artist.py", line 71, in draw_wrapper return draw(artist, renderer) File "D:\Anaconda\Lib\site-packages\matplotlib\figure.py", line 3257, in draw mimage._draw_list_compositing_images( File "D:\Anaconda\Lib\site-packages\matplotlib\image.py", line 134, in _draw_list_compositing_images a.draw(renderer) File "D:\Anaconda\Lib\site-packages\matplotlib\artist.py", line 71, in draw_wrapper return draw(artist, renderer) File "D:\Anaconda\Lib\site-packages\matplotlib\axes\_base.py", line 3181, in draw mimage._draw_list_compositing_images( File "D:\Anaconda\Lib\site-packages\matplotlib\image.py", line 134, in _draw_list_compositing_images a.draw(renderer) File "D:\Anaconda\Lib\site-packages\matplotlib\artist.py", line 71, in draw_wrapper return draw(artist, renderer) File "D:\Anaconda\Lib\site-packages\matplotlib\axis.py", line 1423, in draw self.label.draw(renderer) File "D:\Anaconda\Lib\site-packages\matplotlib\artist.py", line 71, in draw_wrapper return draw(artist, renderer) File "D:\Anaconda\Lib\site-packages\matplotlib\text.py", line 752, in draw bbox, info, descent = self._get_layout(renderer) File "D:\Anaconda\Lib\site-packages\matplotlib\text.py", line 382, in _get_layout w, h, d = _get_text_metrics_with_cache( File "D:\Anaconda\Lib\site-packages\matplotlib\text.py", line 69, in _get_text_metrics_with_cache return _get_text_metrics_with_cache_impl( File "D:\Anaconda\Lib\site-packages\matplotlib\text.py", line 77, in _get_text_metrics_with_cache_impl return renderer_ref().get_text_width_height_descent(text, fontprop, ismath) File "D:\Anaconda\Lib\site-packages\matplotlib\backends\backend_agg.py", line 215, in get_text_width_height_descent self.mathtext_parser.parse(s, self.dpi, prop) File "D:\Anaconda\Lib\site-packages\matplotlib\mathtext.py", line 86, in parse return self._parse_cached(s, dpi, prop, antialiased, load_glyph_flags) File "D:\Anaconda\Lib\site-packages\matplotlib\mathtext.py", line 100, in _parse_cached box = self._parser.parse(s, fontset, fontsize, dpi) File "D:\Anaconda\Lib\site-packages\matplotlib\_mathtext.py", line 2170, in parse result = self._expression.parseString(s) File "D:\Anaconda\Lib\site-packages\pyparsing\core.py", line 1131, in parse_string loc, tokens = self._parse(instring, 0) File "D:\Anaconda\Lib\site-packages\pyparsing\core.py", line 921, in _parseCache value = self._parseNoCache(instring, loc, doActions, callPreParse) File "D:\Anaconda\Lib\site-packages\pyparsing\core.py", line 817, in _parseNoCache loc, tokens = self.parseImpl(instring, pre_loc, doActions) File "D:\Anaconda\Lib\site-packages\pyparsing\core.py", line 3886, in parseImpl loc, exprtokens = e._parse(instring, loc, doActions) File "D:\Anaconda\Lib\site-packages\pyparsing\core.py", line 921, in _parseCache value = self._parseNoCache(instring, loc, doActions, callPreParse) File "D:\Anaconda\Lib\site-packages\pyparsing\core.py", line 817, in _parseNoCache loc, tokens = self.parseImpl(instring, pre_loc, doActions) File "D:\Anaconda\Lib\site-packages\pyparsing\core.py", line 4891, in parseImpl return super().parseImpl(instring, loc, doActions) File "D:\Anaconda\Lib\site-packages\pyparsing\core.py", line 4790, in parseImpl loc, tokens = self_expr_parse(instring, loc, doActions) File "D:\Anaconda\Lib\site-packages\pyparsing\core.py", line 921, in _parseCache value = self._parseNoCache(instring, loc, doActions, callPreParse) File "D:\Anaconda\Lib\site-packages\pyparsing\core.py", line 817, in _parseNoCache loc, tokens = self.parseImpl(instring, pre_loc, doActions) File "D:\Anaconda\Lib\site-packages\pyparsing\core.py", line 3886, in parseImpl loc, exprtokens = e._parse(instring, loc, doActions) File "D:\Anaconda\Lib\site-packages\pyparsing\core.py", line 921, in _parseCache value = self._parseNoCache(instring, loc, doActions, callPreParse) File "D:\Anaconda\Lib\site-packages\pyparsing\core.py", line 856, in _parseNoCache tokens = fn(instring, tokens_start, ret_tokens) File "D:\Anaconda\Lib\site-packages\pyparsing\core.py", line 291, in wrapper ret = func(*args[limit:]) File "D:\Anaconda\Lib\site-packages\matplotlib\_mathtext.py", line 2206, in non_math symbols = [Char(c, self.get_state()) for c in s] File "D:\Anaconda\Lib\site-packages\matplotlib\_mathtext.py", line 1091, in __init__ self._update_metrics() File "D:\Anaconda\Lib\site-packages\matplotlib\_mathtext.py", line 1097, in _update_metrics metrics = self._metrics = self.fontset.get_metrics( File "D:\Anaconda\Lib\site-packages\matplotlib\_mathtext.py", line 286, in get_metrics info = self._get_info(font, font_class, sym, fontsize, dpi) File "D:\Anaconda\Lib\site-packages\matplotlib\_mathtext.py", line 375, in _get_info font, num, slanted = self._get_glyph(fontname, font_class, sym) File "D:\Anaconda\Lib\site-packages\matplotlib\_mathtext.py", line 710, in _get_glyph return super()._get_glyph(fontname, font_class, sym) File "D:\Anaconda\Lib\site-packages\matplotlib\_mathtext.py", line 648, in _get_glyph _log.info("Substituting symbol %s from %s", sym, family) Message: 'Substituting symbol %s from %s' Arguments: ('³', 'STIXGeneral') 2025-07-26 16:29:37,728 - matplotlib.mathtext - WARNING - Font 'default' does not have a glyph for '\xb3' [U+b3], substituting with a dummy symbol. 2025-07-26 16:29:37,728 - matplotlib.mathtext - INFO - Substituting symbol ³ from STIXGeneral --- Logging error --- Traceback (most recent call last): File "D:\Anaconda\Lib\logging\__init__.py", line 1163, in emit stream.write(msg + self.terminator) UnicodeEncodeError: 'gbk' codec can't encode character '\xb3' in position 75: illegal multibyte sequence Call stack: File "D:\PythonProject1\水位计算软件.py", line 606, in <module> root.mainloop() File "D:\Anaconda\Lib\tkinter\__init__.py", line 1505, in mainloop self.tk.mainloop(n) File "D:\Anaconda\Lib\tkinter\__init__.py", line 1968, in __call__ return self.func(*args) File "D:\PythonProject1\水位计算软件.py", line 572, in show_results self.calculator.plot_results() File "D:\PythonProject1\水位计算软件.py", line 274, in plot_results plt.show() File "D:\Anaconda\Lib\site-packages\matplotlib\pyplot.py", line 614, in show return _get_backend_mod().show(*args, **kwargs) File "D:\Anaconda\Lib\site-packages\matplotlib\backend_bases.py", line 3547, in show cls.mainloop() File "D:\Anaconda\Lib\site-packages\matplotlib\backends\_backend_tk.py", line 544, in start_main_loop first_manager.window.mainloop() File "D:\Anaconda\Lib\tkinter\__init__.py", line 1505, in mainloop self.tk.mainloop(n) File "D:\Anaconda\Lib\tkinter\__init__.py", line 1968, in __call__ return self.func(*args) File "D:\Anaconda\Lib\tkinter\__init__.py", line 862, in callit func(*args) File "D:\Anaconda\Lib\site-packages\matplotlib\backends\_backend_tk.py", line 274, in idle_draw self.draw() File "D:\Anaconda\Lib\site-packages\matplotlib\backends\backend_tkagg.py", line 10, in draw super().draw() File "D:\Anaconda\Lib\site-packages\matplotlib\backends\backend_agg.py", line 382, in draw self.figure.draw(self.renderer) File "D:\Anaconda\Lib\site-packages\matplotlib\artist.py", line 94, in draw_wrapper result = draw(artist, renderer, *args, **kwargs) File "D:\Anaconda\Lib\site-packages\matplotlib\artist.py", line 71, in draw_wrapper return draw(artist, renderer) File "D:\Anaconda\Lib\site-packages\matplotlib\figure.py", line 3257, in draw mimage._draw_list_compositing_images( File "D:\Anaconda\Lib\site-packages\matplotlib\image.py", line 134, in _draw_list_compositing_images a.draw(renderer) File "D:\Anaconda\Lib\site-packages\matplotlib\artist.py", line 71, in draw_wrapper return draw(artist, renderer) File "D:\Anaconda\Lib\site-packages\matplotlib\axes\_base.py", line 3181, in draw mimage._draw_list_compositing_images( File "D:\Anaconda\Lib\site-packages\matplotlib\image.py", line 134, in _draw_list_compositing_images a.draw(renderer) File "D:\Anaconda\Lib\site-packages\matplotlib\artist.py", line 71, in draw_wrapper return draw(artist, renderer) File "D:\Anaconda\Lib\site-packages\matplotlib\axis.py", line 1423, in draw self.label.draw(renderer) File "D:\Anaconda\Lib\site-packages\matplotlib\artist.py", line 71, in draw_wrapper return draw(artist, renderer) File "D:\Anaconda\Lib\site-packages\matplotlib\text.py", line 752, in draw bbox, info, descent = self._get_layout(renderer) File "D:\Anaconda\Lib\site-packages\matplotlib\text.py", line 382, in _get_layout w, h, d = _get_text_metrics_with_cache( File "D:\Anaconda\Lib\site-packages\matplotlib\text.py", line 69, in _get_text_metrics_with_cache return _get_text_metrics_with_cache_impl( File "D:\Anaconda\Lib\site-packages\matplotlib\text.py", line 77, in _get_text_metrics_with_cache_impl return renderer_ref().get_text_width_height_descent(text, fontprop, ismath) File "D:\Anaconda\Lib\site-packages\matplotlib\backends\backend_agg.py", line 215, in get_text_width_height_descent self.mathtext_parser.parse(s, self.dpi, prop) File "D:\Anaconda\Lib\site-packages\matplotlib\mathtext.py", line 86, in parse return self._parse_cached(s, dpi, prop, antialiased, load_glyph_flags) File "D:\Anaconda\Lib\site-packages\matplotlib\mathtext.py", line 100, in _parse_cached box = self._parser.parse(s, fontset, fontsize, dpi) File "D:\Anaconda\Lib\site-packages\matplotlib\_mathtext.py", line 2170, in parse result = self._expression.parseString(s) File "D:\Anaconda\Lib\site-packages\pyparsing\core.py", line 1131, in parse_string loc, tokens = self._parse(instring, 0) File "D:\Anaconda\Lib\site-packages\pyparsing\core.py", line 921, in _parseCache value = self._parseNoCache(instring, loc, doActions, callPreParse) File "D:\Anaconda\Lib\site-packages\pyparsing\core.py", line 817, in _parseNoCache loc, tokens = self.parseImpl(instring, pre_loc, doActions) File "D:\Anaconda\Lib\site-packages\pyparsing\core.py", line 3886, in parseImpl loc, exprtokens = e._parse(instring, loc, doActions) File "D:\Anaconda\Lib\site-packages\pyparsing\core.py", line 921, in _parseCache value = self._parseNoCache(instring, loc, doActions, callPreParse) File "D:\Anaconda\Lib\site-packages\pyparsing\core.py", line 817, in _parseNoCache loc, tokens = self.parseImpl(instring, pre_loc, doActions) File "D:\Anaconda\Lib\site-packages\pyparsing\core.py", line 4891, in parseImpl return super().parseImpl(instring, loc, doActions) File "D:\Anaconda\Lib\site-packages\pyparsing\core.py", line 4790, in parseImpl loc, tokens = self_expr_parse(instring, loc, doActions) File "D:\Anaconda\Lib\site-packages\pyparsing\core.py", line 921, in _parseCache value = self._parseNoCache(instring, loc, doActions, callPreParse) File "D:\Anaconda\Lib\site-packages\pyparsing\core.py", line 817, in _parseNoCache loc, tokens = self.parseImpl(instring, pre_loc, doActions) File "D:\Anaconda\Lib\site-packages\pyparsing\core.py", line 3886, in parseImpl loc, exprtokens = e._parse(instring, loc, doActions) File "D:\Anaconda\Lib\site-packages\pyparsing\core.py", line 921, in _parseCache value = self._parseNoCache(instring, loc, doActions, callPreParse) File "D:\Anaconda\Lib\site-packages\pyparsing\core.py", line 856, in _parseNoCache tokens = fn(instring, tokens_start, ret_tokens) File "D:\Anaconda\Lib\site-packages\pyparsing\core.py", line 291, in wrapper ret = func(*args[limit:]) File "D:\Anaconda\Lib\site-packages\matplotlib\_mathtext.py", line 2206, in non_math symbols = [Char(c, self.get_state()) for c in s] File "D:\Anaconda\Lib\site-packages\matplotlib\_mathtext.py", line 1091, in __init__ self._update_metrics() File "D:\Anaconda\Lib\site-packages\matplotlib\_mathtext.py", line 1097, in _update_metrics metrics = self._metrics = self.fontset.get_metrics( File "D:\Anaconda\Lib\site-packages\matplotlib\_mathtext.py", line 286, in get_metrics info = self._get_info(font, font_class, sym, fontsize, dpi) File "D:\Anaconda\Lib\site-packages\matplotlib\_mathtext.py", line 375, in _get_info font, num, slanted = self._get_glyph(fontname, font_class, sym) File "D:\Anaconda\Lib\site-packages\matplotlib\_mathtext.py", line 710, in _get_glyph return super()._get_glyph(fontname, font_class, sym) File "D:\Anaconda\Lib\site-packages\matplotlib\_mathtext.py", line 648, in _get_glyph _log.info("Substituting symbol %s from %s", sym, family) Message: 'Substituting symbol %s from %s' Arguments: ('³', 'STIXGeneral') --- Logging error --- Traceback (most recent call last): File "D:\Anaconda\Lib\logging\__init__.py", line 1163, in emit stream.write(msg + self.terminator) UnicodeEncodeError: 'gbk' codec can't encode character '\xb3' in position 75: illegal multibyte sequence Call stack: File "D:\PythonProject1\水位计算软件.py", line 606, in <module> root.mainloop() File "D:\Anaconda\Lib\tkinter\__init__.py", line 1505, in mainloop self.tk.mainloop(n) File "D:\Anaconda\Lib\tkinter\__init__.py", line 1968, in __call__ return self.func(*args) File "D:\PythonProject1\水位计算软件.py", line 572, in show_results self.calculator.plot_results() File "D:\PythonProject1\水位计算软件.py", line 274, in plot_results plt.show() File "D:\Anaconda\Lib\site-packages\matplotlib\pyplot.py", line 614, in show return _get_backend_mod().show(*args, **kwargs) File "D:\Anaconda\Lib\site-packages\matplotlib\backend_bases.py", line 3547, in show cls.mainloop() File "D:\Anaconda\Lib\site-packages\matplotlib\backends\_backend_tk.py", line 544, in start_main_loop first_manager.window.mainloop() File "D:\Anaconda\Lib\tkinter\__init__.py", line 1505, in mainloop self.tk.mainloop(n) File "D:\Anaconda\Lib\tkinter\__init__.py", line 1968, in __call__ return self.func(*args) File "D:\Anaconda\Lib\tkinter\__init__.py", line 862, in callit func(*args) File "D:\Anaconda\Lib\site-packages\matplotlib\backends\_backend_tk.py", line 274, in idle_draw self.draw() File "D:\Anaconda\Lib\site-packages\matplotlib\backends\backend_tkagg.py", line 10, in draw super().draw() File "D:\Anaconda\Lib\site-packages\matplotlib\backends\backend_agg.py", line 382, in draw self.figure.draw(self.renderer) File "D:\Anaconda\Lib\site-packages\matplotlib\artist.py", line 94, in draw_wrapper result = draw(artist, renderer, *args, **kwargs) File "D:\Anaconda\Lib\site-packages\matplotlib\artist.py", line 71, in draw_wrapper return draw(artist, renderer) File "D:\Anaconda\Lib\site-packages\matplotlib\figure.py", line 3257, in draw mimage._draw_list_compositing_images( File "D:\Anaconda\Lib\site-packages\matplotlib\image.py", line 134, in _draw_list_compositing_images a.draw(renderer) File "D:\Anaconda\Lib\site-packages\matplotlib\artist.py", line 71, in draw_wrapper return draw(artist, renderer) File "D:\Anaconda\Lib\site-packages\matplotlib\axes\_base.py", line 3181, in draw mimage._draw_list_compositing_images( File "D:\Anaconda\Lib\site-packages\matplotlib\image.py", line 134, in _draw_list_compositing_images a.draw(renderer) File "D:\Anaconda\Lib\site-packages\matplotlib\artist.py", line 71, in draw_wrapper return draw(artist, renderer) File "D:\Anaconda\Lib\site-packages\matplotlib\axis.py", line 1423, in draw self.label.draw(renderer) File "D:\Anaconda\Lib\site-packages\matplotlib\artist.py", line 71, in draw_wrapper return draw(artist, renderer) File "D:\Anaconda\Lib\site-packages\matplotlib\text.py", line 752, in draw bbox, info, descent = self._get_layout(renderer) File "D:\Anaconda\Lib\site-packages\matplotlib\text.py", line 382, in _get_layout w, h, d = _get_text_metrics_with_cache( File "D:\Anaconda\Lib\site-packages\matplotlib\text.py", line 69, in _get_text_metrics_with_cache return _get_text_metrics_with_cache_impl( File "D:\Anaconda\Lib\site-packages\matplotlib\text.py", line 77, in _get_text_metrics_with_cache_impl return renderer_ref().get_text_width_height_descent(text, fontprop, ismath) File "D:\Anaconda\Lib\site-packages\matplotlib\backends\backend_agg.py", line 215, in get_text_width_height_descent self.mathtext_parser.parse(s, self.dpi, prop) File "D:\Anaconda\Lib\site-packages\matplotlib\mathtext.py", line 86, in parse return self._parse_cached(s, dpi, prop, antialiased, load_glyph_flags) File "D:\Anaconda\Lib\site-packages\matplotlib\mathtext.py", line 100, in _parse_cached box = self._parser.parse(s, fontset, fontsize, dpi) File "D:\Anaconda\Lib\site-packages\matplotlib\_mathtext.py", line 2170, in parse result = self._expression.parseString(s) File "D:\Anaconda\Lib\site-packages\pyparsing\core.py", line 1131, in parse_string loc, tokens = self._parse(instring, 0) File "D:\Anaconda\Lib\site-packages\pyparsing\core.py", line 921, in _parseCache value = self._parseNoCache(instring, loc, doActions, callPreParse) File "D:\Anaconda\Lib\site-packages\pyparsing\core.py", line 817, in _parseNoCache loc, tokens = self.parseImpl(instring, pre_loc, doActions) File "D:\Anaconda\Lib\site-packages\pyparsing\core.py", line 3886, in parseImpl loc, exprtokens = e._parse(instring, loc, doActions) File "D:\Anaconda\Lib\site-packages\pyparsing\core.py", line 921, in _parseCache value = self._parseNoCache(instring, loc, doActions, callPreParse) File "D:\Anaconda\Lib\site-packages\pyparsing\core.py", line 817, in _parseNoCache loc, tokens = self.parseImpl(instring, pre_loc, doActions) File "D:\Anaconda\Lib\site-packages\pyparsing\core.py", line 4891, in parseImpl return super().parseImpl(instring, loc, doActions) File "D:\Anaconda\Lib\site-packages\pyparsing\core.py", line 4790, in parseImpl loc, tokens = self_expr_parse(instring, loc, doActions) File "D:\Anaconda\Lib\site-packages\pyparsing\core.py", line 921, in _parseCache value = self._parseNoCache(instring, loc, doActions, callPreParse) File "D:\Anaconda\Lib\site-packages\pyparsing\core.py", line 817, in _parseNoCache loc, tokens = self.parseImpl(instring, pre_loc, doActions) File "D:\Anaconda\Lib\site-packages\pyparsing\core.py", line 3886, in parseImpl loc, exprtokens = e._parse(instring, loc, doActions) File "D:\Anaconda\Lib\site-packages\pyparsing\core.py", line 921, in _parseCache value = self._parseNoCache(instring, loc, doActions, callPreParse) File "D:\Anaconda\Lib\site-packages\pyparsing\core.py", line 856, in _parseNoCache tokens = fn(instring, tokens_start, ret_tokens) File "D:\Anaconda\Lib\site-packages\pyparsing\core.py", line 291, in wrapper ret = func(*args[limit:]) File "D:\Anaconda\Lib\site-packages\matplotlib\_mathtext.py", line 2206, in non_math symbols = [Char(c, self.get_state()) for c in s] File "D:\Anaconda\Lib\site-packages\matplotlib\_mathtext.py", line 1091, in __init__ self._update_metrics() File "D:\Anaconda\Lib\site-packages\matplotlib\_mathtext.py", line 1097, in _update_metrics metrics = self._metrics = self.fontset.get_metrics( File "D:\Anaconda\Lib\site-packages\matplotlib\_mathtext.py", line 286, in get_metrics info = self._get_info(font, font_class, sym, fontsize, dpi) File "D:\Anaconda\Lib\site-packages\matplotlib\_mathtext.py", line 375, in _get_info font, num, slanted = self._get_glyph(fontname, font_class, sym) File "D:\Anaconda\Lib\site-packages\matplotlib\_mathtext.py", line 710, in _get_glyph return super()._get_glyph(fontname, font_class, sym) File "D:\Anaconda\Lib\site-packages\matplotlib\_mathtext.py", line 648, in _get_glyph _log.info("Substituting symbol %s from %s", sym, family) Message: 'Substituting symbol %s from %s' Arguments: ('³', 'STIXGeneral')修改后输出完整代码,并且生成的图片的字体需要调整,显示不出来单位
最新发布
07-27
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值