tkinter - 使用带有消息框的 tkinter 时额外的 tkinter 框
问题描述
我的代码是:
import numpy as np
import matplotlib.pyplot as plt
import csv
from tkinter import messagebox
messagebox.showinfo("welcome","welcome to piechart creator!!!")
try:
x=input("enter the file to be fetched:")
outfile = open(x,"r")
except:
messagebox.showinfo("alert","enter the file in csv extension!!!")
else:
file=csv.reader(outfile)
#skip the headers
next(file, None)
row1=input("enter the title of first label:" )
row2=input("enter the title of label2:")
row1= []
row2= []
for row in file:
row1.append(row[0])
row2.append(row[1])
plt.pie(row2, labels=row1)
plt.axis('equal')
messagebox.askyesno("question","do you want the piechart to be created???")
plt.show()
finally:
messagebox.showinfo("message","thank you for using piechart creator.")
我得到了一个额外的 tkinter 盒子——这是为什么呢?
解决方案
如果您没有明确创建Tk()
tkinter 的实例,它将为您执行此操作。您可以通过在脚本开头显式创建根窗口来解决此问题,然后将其隐藏:
import tkinter as tk
root = tk.Tk() # Create window
root.withdraw() # Hide window
推荐阅读
- java - actionPerformed 方法中的错误
- python-3.x - 如果特征已经缩放,则 Lasso 和 Ridge 回归中需要“normalize=True”参数?
- java - 使用 JAR 文件附加快照版本名称
- php - 当codeigniter的标头中缺少令牌字段时,我只想返回JSON错误响应
- php - 我在数据库中有患者信息,现在我想在 Laravel 项目中以另一种形式访问一个人的信息
- python - 姜戈;无法加载静态文件
- c++ - 限制类的实例数
- c# - 使用LINQ分页和存储过程分页的要点是什么?
- php - PHP 不会加载,因为查询不返回任何行
- php - 如何使用数据库扩展 PDO 在 PHP 中编写多查询