1 回答
TA贡献1890条经验 获得超9个赞
这是我知道如何在 tkinter 中导入文件和函数的方法,不确定这是否是正确的方法,但看看我对这两个文件所做的更改
main.py:
from tkinter import *
from function import import_def
root = Tk()
root.geometry('1560x750')
canvas=Canvas(root)
canvas.config(width=1000, height=1560, bg='light grey')
canvas.grid(row=1,column=3, rowspan=1550,ipadx=1300,ipady=750,sticky=NW)
def option_number(x):
if x == "one":
import_def()
variable = StringVar()
variable.set("options")
w = OptionMenu(canvas, variable, "one", "two",command = option_number)
w.config(width=15, height=1,bg='blue')
w.place(x=400,y=100)
root.mainloop()
和函数.py:
from tkinter import *
def import_def():
root = Toplevel()
root.geometry('1560x750')
canvas2 = Canvas(root)
canvas2.config(width=1000, height=1560, bg='red')
canvas2.grid(row=1, column=3, rowspan=1550, ipadx=1300, ipady=750, sticky=NW)
button = Checkbutton(canvas2).place(x=170, y=230)
AND_gate=PhotoImage(file='sad songs.jpg') #set up variables for and_gate
labelimage_and = Label(canvas2, image=AND_gate).place(x=200,y=200)
root.mainloop()
希望对您有帮助,如有疑问或错误,请告诉我。
添加回答
举报