在下面给出的代码中,我只想在选中“土壤”复选框时打开文件打开对话框,然后对“天气”复选框重复同样的操作。
“土壤”检查按钮,“天气”检查按钮和“提交”按钮需要放在GUI框架的左侧,并且滚动条应包含2个打开文件的详细信息(从“文件打开对话框”(格式为“文本”),该对话框将放置在GUI框架的右侧
from tkinter import *
from tkinter import Tk
from tkinter.filedialog import askopenfilename
win = Tk()
frame = Frame(win)
frame.pack()
rightframe = Frame(win)
rightframe.pack( side = RIGHT )
#frame_name = Frame(win)
#frame_address = Frame(win)
win.title("Spatialization of DSSAT model")
w = 800
h = 400
ws = win.winfo_screenwidth()
hs = win.winfo_screenheight()
x = (ws/2) - (w/2)
y = (hs/2) - (h/2)
win.geometry('%dx%d+%d+%d' % (w, h, x, y))
def forCheckbutton1():
filename1 = askopenfilename()
print(filename1)
def forCheckbutton2():
filename2 = askopenfilename()
print(filename2)
def forMuButton1():
win.destroy()
def var_states():
print("soil: %d, \nweather:%d" % (MyVar1.get(), MyVar2.get()))
MyLabel1 = Label(frame, text="Select:")
MyLabel1.grid(row=0, column=0, sticky=W)
MyVar1 = IntVar()
MyVar2 = IntVar()
MyCheckbutton1 = Checkbutton(frame, text="soil", variable=MyVar1, command=forCheckbutton1)
MyCheckbutton1.grid(row=1, column=0, sticky=W)
MyCheckbutton2 = Checkbutton(frame, text="weather", variable=MyVar2, command=forCheckbutton2)
MyCheckbutton2.grid(row=2, column=0, sticky=W)
MyButton1 = Button(frame, text="Submit", width=10, command=forMuButton1)
MyButton1.grid(row=5, columnspan=3)
scrollbar = Scrollbar(rightframe)
scrollbar.pack( side = RIGHT, fill = Y )
myList = Listbox(rightframe, yscrollcommand = scrollbar.set )
forCheckbutton1()
forCheckbutton2()
myList.pack( side = LEFT, fill = BOTH )
scrollbar.config( command = myList.yview )
win.mainloop()
答案 0 :(得分:0)
仅当选中按钮时,才将sapply
和vapply(c(1, 2, 3),
factorial,
FUN.VALUE = numeric(1))
[1] 1 2 6
从主循环中删除以打开对话框。要将框放在左侧,请将forCheckbutton1()
设置为forCheckbutton2()
。为了使滚动条中的文件内容完整,请在功能中打开文件。试试这个:
side