My scrollbar is not working although I've everything done - python

I have a problem with a Tkinter scrollbar. I am doing a large message app (something like messenger), but while I try to create a scrolling frame to display all messages my scrollbar isn't showing, it's empty. It's strange that when I've moved the frame with canvas and scrollbar it has worked. I have no idea what's the problem. I hope you will help me.
Here's the code (it's just a piece of it):
class MainScreen:
def __init__(self, master):
self.frame2 = LabelFrame(master, bd=0)
self.frame2.pack(expand=True, fill=BOTH)
self.msgframe = LabelFrame(self.frame2, bg="#f3f2f1", bd=0)
self.msgframe.pack(side=RIGHT, expand=True, fill=BOTH
self.mdframe = LabelFrame(self.msgframe, bg="#f3f2f1")
self.msgcanvas = Canvas(self.mdframe)
self.msgscrollbar = Scrollbar(self.mdframe, orient=VERTICAL,
command=self.msgcanvas.yview)
self.second_frame1 = LabelFrame(self.msgcanvas, bg='black')
self.msgcanvas.config(yscrollcommand=self.msgscrollbar.set,
bg="green")
self.msgcanvas.configure(
scrollregion=self.msgcanvas.bbox("all"))
self.msgcanvas.create_window((0, 0),
window=self.second_frame1, anchor="nw")
self.mdframe.pack(fill=BOTH, expand=1)
self.msgcanvas.pack(side=LEFT, fill=BOTH, expand=1)
self.msgscrollbar.pack(side=RIGHT, fill=Y)
It looks like that:
enter image description here

Related

How to display Option menu inside a frame in Tkinter?

I am trying to display a bunch of OptionMenu in tkinter. The problem is that once there are too many OptionMenu they go out of screen and they cannot be accessed anymore.
So I thought of implementing a full-screen scrollbar to solve this.
I followed this tutorial - link, in this, the full-screen scrollbar is implemented by putting buttons inside a frame
The code from the tutorial - Working code with buttons
So I tried to use this code but instead of buttons, use OptionMenu.
This is my code
from tkinter import *
import tkinter as tk
from tkinter import ttk
class App(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master)
master.title('ATOM')
master.geometry('650x650')
main_frame = Frame(root)
main_frame.pack(fill=BOTH, expand=1)
# Create A Canvas
my_canvas = Canvas(main_frame)
my_canvas.pack(side=LEFT, fill=BOTH, expand=1)
# Add A Scrollbar To The Canvas
my_scrollbar = ttk.Scrollbar(main_frame, orient=VERTICAL, command=my_canvas.yview)
my_scrollbar.pack(side=RIGHT, fill=Y)
# Configure The Canvas
my_canvas.configure(yscrollcommand=my_scrollbar.set)
my_canvas.bind('<Configure>', lambda e: my_canvas.configure(scrollregion = my_canvas.bbox("all")))
# Create ANOTHER Frame INSIDE the Canvas
second_frame = Frame(my_canvas)
# Add that New frame To a Window In The Canvas
my_canvas.create_window((0,0), window=second_frame, anchor="nw")
length=[1,2,3,4,5,6,7,8,9,10]
variable_rsi_length = tk.StringVar(second_frame)
rsi_len = ttk.OptionMenu(second_frame, variable_rsi_length,*length )
variable_rsi_length.set('14')
for thing in range(100):
ttk.Button(second_frame, text=f'Button {thing} Yo!').grid(row=thing, column=0, pady=10, padx=10)
my_label = Label(second_frame, text="It's Friday Yo!").grid(row=3, column=2)
rsi_len.pack()
self.pack()
if __name__ == "__main__":
root = tk.Tk()
app = App(root)
app.mainloop()
But this doesn't give any error on running in fact it does not even show the new window.
How can I implement this?
What's wrong is that you cannot use pack when its children are being managed by grid.
To be more specific, the error is: _tkinter.TclError: cannot use geometry manager pack inside .!frame.!canvas.!frame which already has slaves managed by grid
So, what you can easily do is just use one type of geometry manager.
Either use only "pack", or only "grid".
Here's a quick solution:
.
.
.
for thing in range(100):
ttk.Button(second_frame, text=f'Button {thing} Yo!').pack()
my_label = Label(second_frame, text="It's Friday Yo!").pack()
rsi_len.pack()
self.pack()
.
.
.

Creating Tkinter Text and making previous text go up

I am creating a game similar to bitlife in Tkinter. Although I have run into a problem. If you recall from bitlife, or any texting platform, you create text, then all the previously created text goes up. This existing text will then go into a scrollable frame (which I have already achieved). I am not asking for the straight up code, just any methods or ideas on how to make the previously created text go up. Thanks!
Not complete but I'm out of time.
Hacked together to show you how to add items to a canvas that very loosely looks like a text message application. Not pretty at all but I only had 10 mins
import tkinter as tk
class Message(tk.Frame):
def __init__(self,parent,name,text):
super().__init__(parent,width=250)
self.lblName = tk.Label(self, text=name, font=('Arial','10'))
self.lblName.grid(row=0,column=0)
self.lblText = tk.Message(self, text=text, font=('Arial','14'))
self.lblText.grid(row=1,column=1)
class MessageFrame(tk.Frame):
def __init__(self,parent):
super().__init__(parent)
# Add a canvas in that frame
self.canvas = tk.Canvas(self, bg="yellow")
self.canvas.grid(row=0, column=0, sticky="news")
# Link a scrollbar to the canvas
self.vsb = tk.Scrollbar(self, orient="vertical", command=self.canvas.yview)
self.vsb.grid(row=0, column=1, sticky='ns')
self.canvas.configure(yscrollcommand=self.vsb.set)
# Create a frame to contain the buttons
self.frame_buttons = tk.Frame(self.canvas, bg="blue")
self.canvas.create_window((0, 0), window=self.frame_buttons, anchor='nw')
self.messages = []
self.msgItems = []
def add_message(self, sender, text):
self.messages.append({'name':sender,'text':text})
self.refresh_msg_list()
def refresh_msg_list(self):
if self.msgItems:
for item in self.msgItems:
item.destroy()
self.msgItems = []
for idx,msg in enumerate(self.messages):
newItem = Message(self.frame_buttons, msg['name'], msg['text'])
#newItem = tk.Button(self.frame_buttons, text=task['task'])
newItem.grid(row=idx,column=0,sticky='news',pady=10)
self.msgItems.append(newItem)
# Update buttons frames idle tasks to let tkinter calculate buttons sizes
self.frame_buttons.update_idletasks()
# Resize the canvas frame to fit 5 messages
first5rows_height = max([task.winfo_height() for task in self.msgItems]) * 5
item_width = max([task.winfo_width() for task in self.msgItems])
##frame_canvas.config(width=first5columns_width + vsb.winfo_width(),
## height=first5rows_height)
self.config(height=first5rows_height,width=item_width+self.vsb.winfo_width())
# Set the canvas scrolling region
self.canvas.config(scrollregion=self.canvas.bbox("all"))
def add_new_item():
pass
def add_first_item():
msg.add_message('SenderName','How are you?')
msg.add_message('SenderName','How are you?')
msg.add_message('SenderName','How are you?')
msg.add_message('SenderName','How are you?')
msg.add_message('SenderName','How are you?')
root = tk.Tk()
root.grid_rowconfigure(0, weight=1)
root.columnconfigure(0, weight=1)
frame_main = tk.Frame(root, bg="gray")
frame_main.grid(sticky='news')
# Create a frame for the canvas with non-zero row&column weights
msg = MessageFrame(frame_main)
msg.grid(row=2, column=0, pady=(5, 0), sticky='nw')
msg.grid_rowconfigure(0, weight=1)
msg.grid_columnconfigure(0, weight=1)
# Set grid_propagate to False to allow 5-by-5 buttons resizing later
msg.grid_propagate(False)
root.after_idle(add_first_item)
root.after(2000,add_new_item)
root.mainloop()

How to custom button and text box using Python GUI?

I would like to ask how to make a custom button and custom text box by using Python?
A custom button should has: transparent feature with only border, round corner, shadow feature, icon need to be placed, animate feature like color changed when click and hover on it.
A custom text box should has: no border but only underline, round corner, transparent feature, icon need to be placed, animate feature like underline becomes thicker when click on it.
Below is my code:
frame = tk.Frame(root, bg='#000000', bd=0)
frame.place(relx=0.5, rely=0.1, relwidth=0.75, relheight=0.1, anchor='n')
entry = tk.Entry(frame, font=60, relief='flat')
entry.place(relwidth=0.65, relheight=1)
button = tk.Button(frame, text="Run", relief='flat', font=40, command=lambda: get_weather(entry.get()))
button.place(relx=0.7, relheight=1, relwidth=0.3)
Here is the reference image design that I prefer:
Any help would be appreciated, thanks!
Tkinter comes with the module ttk which stands for themed tk. It provides a way to create widget themes.
How to do it is under-documented, but tkdocs.com has a good discussion of the fundamentals.
At the end of this question is code which can create frames that have rounded corners, a shadow, and a unique color to represent focus, to serve as an example of what you can do. Answering all your questions is a bit beyond the scope of what stackoverflow is for, but hopefully, this is enough to show that what you want is possible.
import tkinter as tk
from tkinter import ttk
focusBorderImageData = '''
R0lGODlhQABAAPcAAHx+fMTCxKSipOTi5JSSlNTS1LSytPTy9IyKjMzKzKyq
rOzq7JyanNza3Ly6vPz6/ISChMTGxKSmpOTm5JSWlNTW1LS2tPT29IyOjMzO
zKyurOzu7JyenNze3Ly+vPz+/OkAKOUA5IEAEnwAAACuQACUAAFBAAB+AFYd
QAC0AABBAAB+AIjMAuEEABINAAAAAHMgAQAAAAAAAAAAAKjSxOIEJBIIpQAA
sRgBMO4AAJAAAHwCAHAAAAUAAJEAAHwAAP+eEP8CZ/8Aif8AAG0BDAUAAJEA
AHwAAIXYAOfxAIESAHw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GCQYCYA4cwcCEDSYPLOgg4Oro
uhMEdOB84cCAChReB2ZQYcGGkxsGFGCgGzCFCh1QH5jQIW3xugwSzD4QvIIH
4s/PUgiQYcCG4BkC5P/ObpaBhwreq18nb3Z79+8Dwo9nL9I8evjWsdOX6D59
fPH71Xeef/kFyB93/sln4EP2Ebjegg31B5+CEDLUIH4PVqiQhOABqKFCF6qn
34cHcfjffCQaFOJtGaZYkIkUuljQigXK+CKCE3po40A0trgjjDru+EGPI/6I
Y4co7kikkAMBmaSNSzL5gZNSDjkghkXaaGIBHjwpY4gThJeljFt2WSWYMQpZ
5pguUnClehS4tuMEDARQgH8FBMBBBExGwIGdAxywXAUBKHCZkAIoEEAFp33W
QGl47ZgBAwZEwKigE1SQgAUCUDCXiwtQIIAFCTQwgaCrZeCABAzIleIGHDD/
oIAHGUznmXABGMABT4xpmBYBHGgAKGq1ZbppThgAG8EEAW61KwYMSOBAApdy
pNp/BkhAAQLcEqCTt+ACJW645I5rLrgEeOsTBtwiQIEElRZg61sTNBBethSw
CwEA/Pbr778ABywwABBAgAAG7xpAq6mGUUTdAPZ6YIACsRKAAbvtZqzxxhxn
jDG3ybbKFHf36ZVYpuE5oIGhHMTqcqswvyxzzDS/HDMHEiiggQMLDxCZXh8k
BnEBCQTggAUGGKCB0ktr0PTTTEfttNRQT22ABR4EkEABDXgnGUEn31ZABglE
EEAAWaeN9tpqt832221HEEECW6M3wc+Hga3SBgtMODBABw00UEEBgxdO+OGG
J4744oZzXUEDHQxwN7F5G7QRdXxPoPkAnHfu+eeghw665n1vIKhJBQUEADs=
'''
root = tk.Tk()
style = ttk.Style()
borderImage = tk.PhotoImage("borderImage", data=borderImageData)
focusBorderImage = tk.PhotoImage("focusBorderImage", data=focusBorderImageData)
style.element_create("RoundedFrame",
"image", borderImage,
("focus", focusBorderImage),
border=16, sticky="nsew")
style.layout("RoundedFrame",
[("RoundedFrame", {"sticky": "nsew"})])
frame1 = ttk.Frame(style="RoundedFrame", padding=10)
text1 = tk.Text(frame1, borderwidth=0, highlightthickness=0, wrap="word",
width=40, height=4)
text1.pack(fill="both", expand=True)
text1.bind("<FocusIn>", lambda event: frame1.state(["focus"]))
text1.bind("<FocusOut>", lambda event: frame1.state(["!focus"]))
text1.insert("end", "This widget has the focus")
frame2 = ttk.Frame(style="RoundedFrame", padding=10)
text2 = tk.Text(frame2, borderwidth=0, highlightthickness=0, wrap="word",
width=40, height=4)
text2.pack(fill="both", expand=True)
text2.bind("<FocusIn>", lambda event: frame2.state(["focus"]))
text2.bind("<FocusOut>", lambda event: frame2.state(["!focus"]))
text2.insert("end", "This widget does not have the focus")
root.configure(background="white")
frame1.pack(side="top", fill="both", expand=True, padx=20, pady=20)
frame2.pack(side="top", fill="both", expand=True, padx=20, pady=20)
frame1.focus_set()
root.mainloop()
This code was originally posted as an answer to the question Tkinter: How to make a rounded corner text widget?. The original version of this code was written in Tcl in 2007, before stackoverflow existed.

Make scrollbar change length dynamically on Canvas tkinter

I've created a program in Python where i request some HTML through an urllib2 call and I print it on a Canvas item.
HTML source code is quite long so I tried to add a scrollbar to my canvas, but this one doesn't appear when the text is printed
Is there a way to make Scrollbar change dimension dinamically detecting the text lenght? Thank you in advance
This is my source code:
from tkinter import *
import urllib.request
def getURL():
canvas.delete("all")
with urllib.request.urlopen(entry.get()) as response:
received_html = response.read()
print(received_html)
canvas.create_text(10,0,text=received_html, anchor=NW, width=700)
#Widget and item initialization
browser_window = Tk()
browser_window.geometry('900x700') # Size 900, 700
frame = Frame(browser_window) #frame
frame.pack(side=TOP, fill=BOTH, expand=5)
label = Label(frame, text= 'Inserisci URL:')
entry = Entry(frame)
canvas = Canvas(frame) #canvas
scrollbar = Scrollbar(frame, orient=VERTICAL, command=canvas.yview)
#Scrollbar on my canvas
entry.insert(END, "http://jesolo.it")
#canvas configure
canvas.configure(yscrollcommand=scrollbar.set, background='#ffffff',
scrollregion=canvas.bbox("all"))
button = Button(frame, text='Vai', command=getURL )
label.pack(side=TOP)
entry.pack(side=TOP)
button.pack(side=TOP)
scrollbar.pack(side=RIGHT, fill=Y) #Scrollbar pack
canvas.pack(side=LEFT, fill=BOTH, expand=5) #Canvas config
scrollbar.config(command=canvas.yview)
browser_window.mainloop()
Once you add the text to the canvas, you need to update the scrollregion attribute so that the canvas knows how much of its virtual space should be scrollable.
def getURL():
...
canvas.create_text(10,0,text=received_html, anchor=NW, width=700)
canvas.configure(scrollregion=canvas.bbox("all"))

How to add a margin to a tkinter window

So I have so far a simple python tkinter window and i'm adding text, buttons, etc.
snippet:
class Cfrm(Frame):
def createWidgets(self):
self.text = Text(self, width=50, height=10)
self.text.insert('1.0', 'some text will be here')
self.text.tag_configure('big', font=('Verdana', 24, 'bold'))
self.text["state"] = "disabled"
self.text.grid(row=0, column=1)
self.quitw = Button(self)
self.quitw["text"] = "exit",
self.quitw["command"] = self.quit
self.quitw.grid(row=1, column=1)
def __init__(self, master=None):
Frame.__init__(self, master)
self.pack()
self.createWidgets()
the problem is, I want to have about a 15-20 px margin around the window, I looked everywhere, and I couldn't find a solution. Also
self.text.tag_configure('big', font=('Verdana', 24, 'bold'))
doesn't work. Any possible solutions?
Ok, here is the solution I found for question 1:
self.grid(padx=20, pady=20)
Removing .text seems to change the whole frame. I still haven't solved problem 2.
Use the pad options (padx, pady, ipadx, ipady) for the grid command to add padding around the text widget. For example:
self.text.grid(row=0, column=1, padx=20, pady=20)
If you want padding around the whole GUI, add padding when you pack the application frame:
self.pack(padx=20, pady=20)
When you say the tag command doesn't work, how do you define "doesn't work"? Are you getting an error? Does the font look big but not bold, bold but not big, ...? The command looks fine to me, and when I run it it works fine.
Your example doesn't show that you're actually applying that tag to a range of text. Are you? If so, how? If you do the following, what happens?
self.text.insert("1.0", 'is this bold?', 'big')
A quick way to do it is adjust your relief style to flat, then you only have to adjust your border width.
self.Border = Tkinter.Frame(self, relief='flat', borderwidth=4)
You can add an innerFrame with some borderwidth or ipadx,ipady attributes to the root Tk() object. Then put everything in it. And to be sure that innerFrame's width and height values are as the window's, use fill and expand attributes.
root = tk.Tk()
innerFrame = tk.Frame(root, borderwidth=25, bg="red")
innerFrame.pack(fill="both", expand=True)
someButton = tk.Button(innerFrame, text="Button1")
someButton.pack()
or
root = tk.Tk()
innerFrame = tk.Frame(root, bg="red")
innerFrame.pack(ipadx=15, ipady=15, fill="both", expand=True)
someButton = tk.Button(innerFrame, text="Button1")
someButton.pack()

Categories