嗨,我在问自己应该如何使用tkinter的mainloop()。我正在编写一个程序来绘制仿射函数。我做了一个Graph类和2个输入函数+ 2个绘图函数。我的程序是这样组织的:
prog -a arg
我还想知道主循环后是否有一种更新窗口的方法,以便我可以输入另一个功能
答案 0 :(得分:1)
正如@martineau所述,您应该首先组织代码。您可以执行以下操作:
{
"access_token": "eyJ0eXAiOiJKV1QiLCJhbsdfsdfsdfsdfcsdcsdvarglkwelkrmgmasdmnfjtugnasmdfisdfmmmmpeirhg_-e60s72zgV8Gn2hUiWwlelNQhJongUW6fxwD42c1N5u4R2JJdrj5V_bIwnvY_C_l5wHlIFSQRE1E-5KzP7WG9XjmV9oXRXXGjNhwRqEocGdiEMjcibyiYQNZmG2h-GbsTKvCc21hRNhyRF_y4mdwVUytAXT68TuwZxsTbjUzEvPdwd2JZaFnD9Elo7akSk2ROnRMxN70fsoLzEK71kbzoYkti1jX_V8i_s6K0wmLma-x4nc2kW5mpFM0R9NPqH-kGf-4ZUKim03frifpsGl6Nqo-eN5oZ-b6YgK56mSjxpxQ",
"expires_in": 3600,
"token_type": "Bearer"
}
那它做什么?它创建一个import tkinter as tk
class Graph:
def __init__(self, master):
#I init some variables
self.master = master
def input_function(self):
#I input the function
def input_dimensions(self):
#I input the dimensions
def draw_grid(self):
#I draw the x and y axis with graduation
#Should I put a mainloop() here ?
def draw_function(self):
#I draw the function
#Should I put a mainloop()here ?
def main(self):
self.input_function()
self.input_dimensions()
self.draw_grid()
self.draw_function()
#Should I put a mainloop() here ?
if __name__ == '__main__':
root = tk.Tk()
graph_class_object = Graph(master=root)
graph_class_object.main()
root.mainloop()
对象,然后将其传递给类Tk
。如您所见,我将Graph
对象作为变量Tk
传递。因此,您可以将master
用作任何新的tkinter小部件(例如self.master
,Button
等)的父级。
Label
按钮初始化代码也应该在您的 self.button = tk.Button(self.master, text="Button", height=1, width=20)
self.button.pack(side="top", padx=50, pady=5)
函数中