简体   繁体   English

如何使用tkinter Scale小部件的值连续更改图像

[英]How to continuously change an image using the value of a tkinter Scale widget

I have a bunch of images which I want the user to select using a scale. 我有一堆图像,希望用户使用比例尺进行选择。 As the user updates the scale value, I want the GUI to update which image is shown. 当用户更新比例值时,我希望GUI更新显示的图像。

I have just started dealing with GUIs and I'm stuck. 我刚刚开始处理GUI,但遇到了麻烦。 I've managed to print the new values from the scale using the command keyword argument of the Scale widget. 我已经成功地使用Scale小部件的command关键字参数从比例中打印了新值。 However, it is not clear how I can get this value to update the image on the interface. 但是,尚不清楚如何获取此值以更新界面上的图像。

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()

设置echo_time.trace(slider_callback) ,(只要echo_time更改值,就会调用给定的方法),然后在slider_callback设置root_window.iconify(file_name)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何打印tkinter Scale小部件的值? - How to print the value of a tkinter Scale widget? Tkinter:如何使用 scale-widget 的值来更改 label-widget 的文本? - Tkinter: How do I use the value of a scale-widget to change the text of a label-widget? 如何从 tkinter Scale 小部件显示中删除比例值? - How to remove scale value from tkinter Scale widget display? 如何根据Python中另一个tkinter`Scale`小部件的值来控制tkinter`Scale`小部件的值? - How control the value of a tkinter `Scale` widget depending on the value of another tkinter `Scale` widget in Python? 如何更改显示tkinter Scale小部件当前值的一侧? - How to change the side where the current value of the tkinter Scale widget is being displayed? 如何在Python中为tkinter Scale小部件设置初始值? - How set the initial value for a tkinter Scale widget in Python? 如何在Python中检索tkinter ttk Scale小部件的整数值? - How to retrieve the integer value of tkinter ttk Scale widget in Python? Python / Tkinter:如何使用Entry小部件更改Label小部件? - Python/Tkinter: How to change Label widget with using Entry widget? 如何在Tkinter中使用Scale小部件更新matplotlib - How to update matplotlib with Scale widget in Tkinter 如何将Tkinter Scale小部件的状态设置为Disabled? - How to set the state of a tkinter Scale widget to disabled?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM