因此,我制作了一个程序,该程序可以找到一个数字因数 我的问题是如何将名称打印到tkinter中 我先问用户名,然后问什么号码并显示该数字的因数 然后程序会询问用户是否要输入另一个 0表示退出 当他在tkinter中输入0以他的名字表示感谢时,我就想要 “谢谢!使用我的程序的名字!”
我对tkinter相当陌生,我是一个非常糟糕的学习者 我不知道如何在tkinter中写他的名字
from tkinter import *
print("Finding Factors Program by Joshua Lozada")
name=input("what is your name?")
print ("Hello",name, " Welcome To My Finding factors Program")
def factor_finder(x):
print("The factors of",x,"are:")
for i in range(1, x + 1):
if x % i == 0:
print(i)
while True:
try:
num = int(input("Enter an integer (0 to exit): "))
if num == 0:
window = Tk()
window.title("Thank you!")
window.configure(background="black")
Label (window, bg="black")
Label(window, text = "Thank you for using my program!" , bg
="black", fg="white", font= "none 12 bold") .grid(row=0, column=0,
sticky=W)
break
factor_finder(num)
except ValueError:
print("Sorry, you must enter an integer")
我希望节目一旦结束显示 tkinter并感谢您使用我的程序!
答案 0 :(得分:0)
您应该将tkinter
代码放在游戏循环之外;也就是说,终止时,主循环应退出(break
),然后执行tkinter
代码:
也许是这样吗?
import tkinter as tk
print("Finding Factors Program by Joshua Lozada")
name=input("what is your name?")
print ("Hello",name, " Welcome To My Finding factors Program")
def factor_finder(x):
print("The factors of",x,"are:")
for i in range(1, x + 1):
if x % i == 0:
print(i)
while True:
try:
num = int(input("Enter an integer (0 to exit): "))
if num == 0:
break
factor_finder(num)
except ValueError:
print("Sorry, you must enter an integer")
window = tk.Tk()
window.title("Thank you!")
window.configure(background="black")
tk.Label(window, bg="black")
tk.Label(window, text="Thank you for using my program!", bg="black", fg="white", font= "none 12 bold").grid(row=0, column=0, sticky=W)
window.mainloop()
答案 1 :(得分:0)
这是您需要执行的操作,以便在tkinter窗口上打印名称和消息
Label(window, text = "Thank you "+name+" for using my program" , bg
="black", fg="white", font= "none 12 bold") .grid(row=0, column=0,
sticky=W)