Quantcast
Channel: User martineau - Stack Overflow
Viewing all articles
Browse latest Browse all 44

Answer by martineau for tkinter grid method not properly placing the button

$
0
0

As others have pointed out in comments, rows and columns with nothing in them take up no space, and the only gridded widget you have is a custom Button at position row=250, column=250.

You can change that and make tkinter consider even empty rows and columns by configuring their relative "weights" using the rowconfigure() and columnconfigure() methods as shown below. Here's some documentation.

import tkinter as tkroot = tk.Tk()root.minsize(500,500)# Specify minimum grid row and column sizes for a grid of given dimensions.height, width = 250, 250for column in range(width):    root.columnconfigure(column, weight=1)for row in range(height):    root.rowconfigure(row, weight=1)im = tk.PhotoImage(height=1, width=1)my_button = tk.Button(root, height=1, width=1, image=im, bg="black")my_button.grid(row=250, column=250)root.mainloop()

If you make the changes shown above to your script, you should get something like what is shown below where the Button is not being displayed in the lower right corner. I'm not sure if that is what you want because you have not indicated what the maximum grid positions you intend to use are — but you can rectify that by changing the values assigned to the width and height variables in the code above.

Result:

screenshot


Viewing all articles
Browse latest Browse all 44

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>