我正在构建一个计算器,我正在按下按钮并在屏幕上显示值。为此,我创建了两个不同的 .py 文件(我想使用模块)。按照您的要求,我将使用最简单的代码更新帖子以重现该问题。这是计算器布局:
from tkinter import *
from screenvalue import value
root=Tk()
frame=Frame(root) #frame for the buttons and other options
frame.config(background="#40798C")
frame.pack()
#------------------------ SCREEN ----------------------
screen=Text(frame, width=150, height=5)
screen.grid(row=1, column=1, padx=5, pady=5, columnspan=15)
screen.config(background="#E2E2E2", fg="black")
#--------button---------------------------------
button4=Button(frame, text="4", width=10, padx=0, pady=0, command=value)
button4.grid(row=4,column=11)
root.mainloop()
这是我正在使用的模块
from tkinter import *
character=StringVar()
def value():
return character.set("4")
我将模块的名称从Typing.py 更改为screenvalue.py。你知道发生了什么吗?它们都在同一个文件夹中
白衣染霜花
慕工程0101907
相关分类