好吧,我是一个初学者。
我用tkinter创建了一个程序,将其组织起来,将它们分为3个二级归档和1个主体,它们都是.py,如果它们分别执行,则它们可以工作,但是当我将二级文件导入主体代码时,该条目就变成了在0
看:
from tkinter import *
def average_opt():
import average
def necessarygrade_opt():
import necessary_grade
def yourgrade_opt():
import grade
root = Tk()
root.title('Average Calculator')
root.geometry('200x200')
# options for user
Button(root, text='Average', command=average_opt, width=20).place(x=25, y=30)
Button(root, text='Necessary Grade', command=necessarygrade_opt, width=20).place(x=25, y=90)
Button(root, text='Your Grade', command=yourgrade, width=20).place(x=25, y=150)
root.mainloop()
平均为:
from tkinter import *
root2 = Tk()
root2.title('Average Calculator')
root2.geometry('400x400')
def calculate():
average = (2 * grade1.get() + 2 * grade2.get() + grade3.get()) / 5
Label(root2, text='Your average is {}'.format(average), font=('comic sans ms', 16, 'bold')).place(x=55, y=250)
# Labels: Show informations for user
grade1_label = Label(root2, text='Test 1 grade:', font=('comic sans ms', 13, 'bold')).place(x=35, y=30)
grade2_label = Label(root2, text='Test 2 grade:', font=('comic sans ms', 13, 'bold')).place(x=25, y=80)
grade3_label = Label(root2, text='Work's Grade:', font=('comic sans ms', 13, 'bold')).place(x=15, y=130)
# Entrys: Colect the informations from users
grade1 = IntVar()
grade2 = IntVar()
grade3 = IntVar()
grade1_entry = Entry(root2, textvariable=grade1, width=30).place(x=180, y=37)
grade2_entry = Entry(root2, textvariable=grade2, width=30).place(x=180, y=87)
grade3_entry = Entry(root2, textvariable=grade3, width=30).place(x=180, y=137)
# Buttons: Execute a command
Button(root2, text='Calculate', command=calculate, width=50).place(x=20, y=180)
root2.mainloop()
必要的等级是:
from tkinter import *
root3 = Tk()
root3.title('Nota Necessária')
root3.geometry('400x400')
def calculate2():
nota = (corrects.get() / total.get()) * 10
Label(root3, text='Your grade was {}'.format(grade), font=('comic sans ms', 14, 'bold')).place(x=70, y=250)
# Labels: Show informations for user
escores_totais_label = Label(root3, text='Total:', font=('comic sans ms', 13, 'bold')).place(x=25, y=30)
escores_atingidos_label = Label(root3, text='Corrects:', font=('comic sans ms', 13, 'bold')).place(x=15, y=80)
# Entry: Colect the informations from users
total = IntVar()
corrects = IntVar()
escores_totais_entry = Entry(root3, textvariable=total, width=30).place(x=180, y=37)
escores_atingidos_entry = Entry(root3, textvariable=corrects, width=30).place(x=180, y=87)
# Buttons: Execute a command
Button(root3, text='Calculate', command=calculate2, width=50).place(x=20, y=180)
root3.mainloop()
等级是:
from tkinter import *
root4 = Tk()
root4.title('Nota')
root4.geometry('400x400')
def calculate3():
bimestral = (5 * target.get() - 2 * grade1.get() - grade2.get()) / 2
Label(root4, text='The grade to arrive\in the average {} is {}'.format(target.get(), bimestral),
font=('comic sans ms', 14, 'bold')).place(x=55, y=250)
# Labels: Show informations for user
grade1_label = Label(root4, text='Test 1:', font=('comic sans ms', 13, 'bold')).place(x=35, y=30)
grade2_label = Label(root4, text='Work's Grade:', font=('comic sans ms', 13, 'bold')).place(x=15, y=80)
target_label = Label(root4, text='Target Average:', font=('comic sans ms', 13, 'bold')).place(x=20, y=130)
# Entry: Colect the informations from users
grade1 = IntVar()
grade2 = IntVar()
target = IntVar()
grade1_entry = Entry(root4, textvariable=grade1, width=30).place(x=180, y=37)
grade2_entry = Entry(root4, textvariable=grade2, width=30).place(x=180, y=87)
target_entry = Entry(root4, textvariable=target, width=30).place(x=180, y=137)
# Buttons: Execute a command
Button(root4, text='Calculate', command=calculate3, width=50).place(x=20, y=180)
root4.mainloop()
我知道这很乱,因为我在编码过程中迷失了自己。
这是基于我的学校系统,我不知道其他地方是否使用它。
提前致谢。
(对不起我的英语大声笑)
python大神给出的解决方案
基本上,您可以将root? = Tk()
更改为root? = Toplevel()
并在三个模块.py文件中删除root?.mainloop()
。
您还需要修复以下问题:
在主要情况下,command=yourgrade
按钮的command=yourgrade_opt
应该是Your Grade
。
在grade.py
中,将"
用作grade2_label
的文本:text="Work's Grade:"
在average.py
中,将"
用作grade3_label
的文本:text="Work's Grade:"
在calculate2()
内的necessary_grade.py
中,.format(grade)
应该为.format(nota)
由于某些原因,我无法从以下代码中找出原因:>>> from pytz import timezone >>> timezone('America/Chicago') 我得到:<DstTzInfo 'America/Chicago' LMT-1 day, 18:09:00 STD…
Python:同时在for循环中添加到列表列表 - python我想用for循环外的0索引值创建一个新列表,然后使用for循环添加到相同的列表。我的玩具示例是:import random data = ['t1', 't2', 't3'] masterlist = [['col1', 'animal1', 'an…
用大写字母拆分字符串,但忽略AAA Python Regex - python我的正则表达式:vendor = "MyNameIsJoe. I'mWorkerInAAAinc." ven = re.split(r'(?<=[a-z])[A-Z]|[A-Z](?=[a-z])', vendor) 以大写字母分割字符串,例如:'我的名字是乔。 I'mWorkerInAAAinc”变成…
Python:来自dict系列的Pandas数据框 - python我有一个熊猫数据框:type(original) pandas.core.frame.DataFrame 其中包括系列对象original['user']:type(original['user']) pandas.core.series.Series original['user']指向许多命令:…
我不明白为什么sum(df ['series'])!= df ['series']。sum() - python我正在汇总一系列值,但是根据我的操作方式,我会得到不同的结果。我尝试过的两种方法是:sum(df['series']) df['series'].sum() 他们为什么会返回不同的值?示例代码。s = pd.Series([ 0.428229 , -0.948957 , -0.110125 , 0.791305 , 0…