0

我有一堆图像,我希望用户使用比例尺进行选择。当用户更新比例值时,我希望 GUI 更新显示的图像。

我刚刚开始处理 GUI,但我被困住了。我已经设法使用小部件的command关键字参数从比例打印新值Scale。但是,目前尚不清楚如何获取此值来更新界面上的图像。

class MainProgram():

def AcquireDicomFiles(self):

    # HERE I GET THE IMAGES PATHS. IT WORKS FINE.


def GUI(self):

    root_window = Tk()

    slice_number = DoubleVar()
    bar_length = 200

    main_title = Label(root_window, text="Seleção de corte e echo").pack()

    scale_slice = Scale(root_window, variable=slice_number, orient=HORIZONTAL, from_=1, to=24, length=bar_length,
                  cursor="hand", label="Slice Number", command=MainProgram().get_slice_value)
    scale_slice.pack(anchor=CENTER)

    echo_time = DoubleVar()
    scale_echo = Scale(root_window, variable=echo_time, orient=HORIZONTAL, from_=1, to=6, length=bar_length,
                  cursor="hand", label="Echo Time")
    scale_echo.pack(anchor=CENTER)

    imagefile = Image.open("image.png")
    tk_image = ImageTk.PhotoImage(imagefile)

    panel = Label(root_window, image=tk_image).pack(fill="both", expand="yes")

    root_window.mainloop()

def get_slice_number(self,user_slice_number):
    user_slice_number = np.int(user_slice_number)

def showImage(self): 

    # Code below works fine for user input in terminal. It uses user_slice_number and user_echo_time to find image. I want these two values to come from the pair of scales

    # indexes = np.where(slice_and_echo[:][0] == user_slice_number)[0] #indexes of the elements where the user input match the element

    # for i in indexes: #Go through index values. Check and record those in which echo time (element) matches user input
    #     if slice_and_echo[i][1] == user_echo_time:
    #         selected_echo_time = user_echo_time
    #         selected_slice_number = slice_and_echo[i][0]
    #         index = i

    # file_path = os.path.join(dcm_folder, dcm_files[index]) #path of the file whose index match user input
    # dcm_read = dicom.read_file(file_path) #read file user wants
    # dcm_pixel_values = dcm_read.pixel_array #extract pixel values


slice_and_echo = MainProgram().AcquireDicomFiles()

MainProgram().GUI()
4

1 回答 1

-1

Set echo_time.trace(slider_callback), (它调用给它的方法,只要echo_time改变值),然后在 内slider_callback,你设置root_window.iconify(file_name).

于 2017-07-25T10:12:09.333 回答