<tfoot id='HM5XW'></tfoot>
      <legend id='HM5XW'><style id='HM5XW'><dir id='HM5XW'><q id='HM5XW'></q></dir></style></legend>

      <i id='HM5XW'><tr id='HM5XW'><dt id='HM5XW'><q id='HM5XW'><span id='HM5XW'><b id='HM5XW'><form id='HM5XW'><ins id='HM5XW'></ins><ul id='HM5XW'></ul><sub id='HM5XW'></sub></form><legend id='HM5XW'></legend><bdo id='HM5XW'><pre id='HM5XW'><center id='HM5XW'></center></pre></bdo></b><th id='HM5XW'></th></span></q></dt></tr></i><div id='HM5XW'><tfoot id='HM5XW'></tfoot><dl id='HM5XW'><fieldset id='HM5XW'></fieldset></dl></div>
        • <bdo id='HM5XW'></bdo><ul id='HM5XW'></ul>

        <small id='HM5XW'></small><noframes id='HM5XW'>

      1. 如何使用 tkinter 使用网格功能显示不同的图像?

        how to display different images using grid function using tkinter?(如何使用 tkinter 使用网格功能显示不同的图像?)
        <tfoot id='Q21Xt'></tfoot>

        • <i id='Q21Xt'><tr id='Q21Xt'><dt id='Q21Xt'><q id='Q21Xt'><span id='Q21Xt'><b id='Q21Xt'><form id='Q21Xt'><ins id='Q21Xt'></ins><ul id='Q21Xt'></ul><sub id='Q21Xt'></sub></form><legend id='Q21Xt'></legend><bdo id='Q21Xt'><pre id='Q21Xt'><center id='Q21Xt'></center></pre></bdo></b><th id='Q21Xt'></th></span></q></dt></tr></i><div id='Q21Xt'><tfoot id='Q21Xt'></tfoot><dl id='Q21Xt'><fieldset id='Q21Xt'></fieldset></dl></div>
            <bdo id='Q21Xt'></bdo><ul id='Q21Xt'></ul>

                <legend id='Q21Xt'><style id='Q21Xt'><dir id='Q21Xt'><q id='Q21Xt'></q></dir></style></legend>
                    <tbody id='Q21Xt'></tbody>
                • <small id='Q21Xt'></small><noframes id='Q21Xt'>

                • 本文介绍了如何使用 tkinter 使用网格功能显示不同的图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想使用 grid() 显示文件夹中的图像.但是当我尝试使用以下代码时,我得到了单个图像迭代的输出.

                  I want to display the images in the folder using grid(). But when I tried with the following code, I got the output with single image iterated.

                  我的代码:

                  def messageWindow():
                      win = Toplevel()
                      path = 'C:UsersHPDesktopdataset'
                      for r in range(7):
                          for c in range(10):
                              for infile in glob.glob(os.path.join(path,'*.jpg')):
                                im = Image.open(infile)
                                resized = im.resize((100, 100),Image.ANTIALIAS)
                                tkimage = ImageTk.PhotoImage(resized)
                                myvar=Label(win,image = tkimage)
                                myvar.image = tkimage
                                myvar.grid(row=r,column=c)   
                  root = Tk()
                  button = Button(app, text='Images in DataSet',command = messageWindow)
                  button.pack(padx = 1, pady = 1,anchor='ne')
                  button.place( x = 850, y = 60)
                  root.mainloop()  
                  

                  当我运行这段代码时,5分钟后会弹出一个子窗口,它会显示一个像这样的图像;

                  When I run this code, after 5 minutes a child window will popup, and it will display a single image like this;

                  但是如何获取数据集中的所有图像呢?欢迎任何建议.感谢您的支持!

                  But how to get all the images in the dataset? Any suggestions are welcome. Tkanks for your support!

                  推荐答案

                  正如我在评论中所说,您在网格的每一行和每一列中都放置了相同的图像.以下是如何使用内置 divmod() 函数迭代计算每一行的行和列,基于 COLUMNS 的数量,您希望根据 image_count:

                  As I said in a comment, you're putting the same image in every row and column of the grid. Here's how to avoid that using the built-in divmod() function to iteratively compute the row and column for each one, based on the number of COLUMNS you want to display in each row based on the current value of image_count:

                  def messageWindow():
                      win = Toplevel()
                      path = r'C:UsersHPDesktopdataset'
                      COLUMNS = 10
                      image_count = 0
                      for infile in glob.glob(os.path.join(path, '*.jpg')):
                          image_count += 1
                          r, c = divmod(image_count-1, COLUMNS)
                          im = Image.open(infile)
                          resized = im.resize((100, 100), Image.ANTIALIAS)
                          tkimage = ImageTk.PhotoImage(resized)
                          myvar = Label(win, image=tkimage)
                          myvar.image = tkimage
                          myvar.grid(row=r, column=c)
                      win.mainloop()  # Not sure if you need this, too, or not...
                  

                  这篇关于如何使用 tkinter 使用网格功能显示不同的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  groupby multiple coords along a single dimension in xarray(在xarray中按单个维度的多个坐标分组)
                  Group by and Sum in Pandas without losing columns(Pandas中的GROUP BY AND SUM不丢失列)
                  Group by + New Column + Grab value former row based on conditionals(GROUP BY+新列+基于条件的前一行抓取值)
                  Groupby and interpolate in Pandas(PANDA中的Groupby算法和插值算法)
                  Pandas - Group Rows based on a column and replace NaN with non-null values(PANAS-基于列对行进行分组,并将NaN替换为非空值)
                  Grouping pandas DataFrame by 10 minute intervals(按10分钟间隔对 pandas 数据帧进行分组)

                  <i id='LP3Cf'><tr id='LP3Cf'><dt id='LP3Cf'><q id='LP3Cf'><span id='LP3Cf'><b id='LP3Cf'><form id='LP3Cf'><ins id='LP3Cf'></ins><ul id='LP3Cf'></ul><sub id='LP3Cf'></sub></form><legend id='LP3Cf'></legend><bdo id='LP3Cf'><pre id='LP3Cf'><center id='LP3Cf'></center></pre></bdo></b><th id='LP3Cf'></th></span></q></dt></tr></i><div id='LP3Cf'><tfoot id='LP3Cf'></tfoot><dl id='LP3Cf'><fieldset id='LP3Cf'></fieldset></dl></div>
                    <tbody id='LP3Cf'></tbody>

                  <small id='LP3Cf'></small><noframes id='LP3Cf'>

                    <bdo id='LP3Cf'></bdo><ul id='LP3Cf'></ul>

                    • <legend id='LP3Cf'><style id='LP3Cf'><dir id='LP3Cf'><q id='LP3Cf'></q></dir></style></legend>
                        <tfoot id='LP3Cf'></tfoot>