我刚开始学习Python,我正试图创建一个矿物计数器,只使用微观岩相学中的字母,但我在将Python代码传递给Tkinker时遇到了问题。你们能给我一些关于如何让我的成果发挥作用的建议吗?我发现即使在在线教程中使用get()
方法也很有挑战性
你们能教这个noob吗?谢谢大家!
我的原始代码:
# define sample
sample = "qreqqwer"
# mineral q:
mineralq= "q"
countq = sample.count(mineralq)
# print count of q
print("The quantity of q is: ", countq)
我用Tkinker制作的结构:
from tkinter import *
import tkinter as tk
# Window
window=tk.Tk()
window.title("Mineral Counter")
window.geometry("800x1000")
window.configure(bg="#00090F")
inputUser=tk.Text(window,width=225,height=5,font=("Arial bold",12),wrap="word", bg="#00090F", fg="white")
inputUser.pack()
# define sample
# mineral q:
countq = inputUser.count("q")
# print count of q
output.insert(tk.INSERT,countq)
output=tk.Text(window,width=20,height=2,font=("Arial bold",12), bg="#00090F", fg="white")
output.pack()
window.mainloop()
您需要一个按钮来更新代码,因为最初
Text
框是空的,因此q
没有出现,因此无法插入任何内容试试这个:
首先创建一个按钮,该按钮具有在输入数据后单击的功能
现在定义单击按钮时调用的函数
希望它消除您的疑虑,如果有任何错误,请告诉我
干杯
相关问题 更多 >
编程相关推荐