• Register
0 votes
2.2k views

Problem :

I am trying to make the rss reader using my tkinter library, and in one of the methods I am creating the text widget. It displays pretty fine until I try to add the scrollbars to it.

Below is my code before the scrollbars:

def txtcreate_text(tbxself, root):
tbxself.textbox = Text(root, height = 10, width = 79, wrap = 'word')
tbxself.textbox.grid(column = 0, row = 0)

Below is my code after scrollbars :

def txtcreate_text(tbxself, root):
tbxself.textbox = Text(root, height = 10, width = 79, wrap = 'word')
sbvertscroll = ttk.Scrollbar(root)
sbvertscroll.config(command=tbxself.textbox.yview)
sbvertscroll.pack(side="right", fill="y", expand=False)
tbxself.textbox.config(yscrllcommand=sbvertscroll.set)
tbxself.textbox.pack(side="left", fill="both", expand=True)
tbxself.textbox.grid(column = 0, row = 0)

This gives me below error :

"_tkinter.TclError: cannot use geometry manager pack inside .56155888 which already has slaves managed by grid on the line vertscroll.pack(side="right", fill="y", expand=False)"

 

Any ideas how to fix above error?

6 5 3
7,540 points

1 Answer

0 votes

Solution :

As per the docs, please do not mix the pack and the grid in your same master window:

Warning: Never mix the grid and pack in your same master window. Tkinter will happily spend your rest of the lifetime trying to negotiate the solution that both managers are happy with it. Instead of waiting for that, try to kill your application, and make sure to have another look at the code. The common mistake is to use your wrong parent for some of your widgets.

So if you want to call grid on the textbox, then please do not call pack on the scrollbar.

 

9 7 4
38,600 points

Related questions

1 vote
1 answer 274 views
274 views
Problem: I installed tkinter and I wrote this code to check if this works or not: import tkinter as tink a = tink.Tink() a.title('Total Seconds') button = tink.Button(a, text='Welcome', width=40, command=a.destroy) button.pack() a.mainloop() But after running this ... ", line 2, in <module> a = tink.Tink() AttributeError: module 'tkinter' has no attribute 'Tink' Can anyone help me to solve this?
asked Apr 29 samhaz 5k points
0 votes
1 answer 1.1K views
1.1K views
Problem : I am learning Python. I have written a basic python script and trying to run the basic python script on the server: import matplotlib.pyplot as plot import numpy as nump x = nump.random.randn(80) y = nump.random.randn(80) plot.scatter(x, y, s=30) ... , useTk, sync, use) _tkinter.TclError: no display name and no $DISPLAY environment variable Why am I facing above error? How can I fix it?
asked Feb 25 mphil 2.3k points
0 votes
1 answer 36 views
36 views
Cannot create controller in thread that did not call Looper.prepare () What does the following exception mean? How can I fix it? Here is the code: Toast toast = Toast.makeText (mContext, "Something", Toast.LENGTH_SHORT); This is the exception: Java.lang.RuntimeException: Cannot ... :121)      on Android.widget.Toast. <init> (Toast.Java:68)      on Android.widget.Toast.makeText (Toast.Java:231)
asked Aug 17 game 4.6k points