How to add a scrollbar to a tkinter window? [duplicate] - python

This question already has answers here:
Adding a scrollbar to a group of widgets in Tkinter
(3 answers)
Closed 2 years ago.
I don't know how to add a scrollbar to this window. Here's the code:
def winHelp():
winHelp = tk.Tk()
winHelp.geometry("700x700")
winHelp.title("Help")
line1label = tk.Label(winHelp, text="Radioactive Decay Calculator: \n")
There will be some text here that will fill up the window:
line1label.grid(row=0)
line1label.config(justify=LEFT)

If you are talking a Tkinter scrollbar, you should tag Tkinter also. For applying Tkinter scrollbar you should use below code.scroll_bar = Scrollbar(master, option,..)
where master is a parent window.

Related

Can you make a button using the tkinter canvas? [duplicate]

This question already has answers here:
How to make a Button using the tkinter Canvas widget?
(2 answers)
Closed 2 years ago.
I want to make a button using the Tkinter canvas. But I can't find anything on how to do it. I've tried using the regular button widget, but those don't display nor do anything. If anyone has a way of doing, please tell me!
This works.
canvas.create_rectangle(x1, y1, x1+w, y1+h, fill=fill, tags=tag, width=width)
canvas.tag_bind(tag, "<Button-1>", function)
2nd line is key :)
This generates a button on a canvas, the canvas setting should be changeable without changing the button. Found here https://python-tricks.com/button-in-tkinter/
import tkinter as tk
screen = tk.Tk()
#Screen size
screen.geometry('300x300')
#Button
button_tk = tk.Button(screen, text="Hello")
button_tk.pack(side='top')
screen.mainloop()

How do I make a drop down menu on the title bar [duplicate]

This question already has answers here:
Can I change the title bar in Tkinter?
(11 answers)
Closed 3 years ago.
I'm creating a simple gui application in python. I know the existing drop down menu option in tkinter but I want it to appear on the title bar. Similar to what you can find on the gnome-calculator in ubuntu18.04 (selecting between modes). How to achieve this using python3 tkinter?
You will need to create a frameless window using self.overrideredirect(True) and put a widget representing the title bar on the top of the window. Put your dropdown into that widget. Simple example:
import tkinter
from tkinter import ttk
class App(tkinter.Tk):
def __init__(self):
tkinter.Tk.__init__(self)
self.title("Example")
self.overrideredirect(True)
self.title_bar = ttk.Combobox(values=["Mode 1", "Mode 2"])
self.title_bar.set("Mode 1")
self.title_bar.state(["readonly"])
self.title_bar.pack()
app = App()
app.mainloop()
Note that in this example the window is not visible in the taskbar. See Tkinter, Windows: How to view window in windows task bar which has no title bar?

Detecting mouse clicks in python Tkinter canvas [duplicate]

This question already has an answer here:
How to bind a click event to a Canvas in Tkinter? [closed]
(1 answer)
Closed 5 years ago.
Is there a way to detect when the mouse is clicked on a Tkinter canvas in python, only using modules which are downloaded with the python package?
I guess a possible answer would be
root = Tk()
canvas= Canvas(root, width=100, height=100)
canvas.bind("<Key>", key)
canvas.bind("<Button-1>", callback)
canvas.pack()
Where key and callback are functions you have to define yourself.
From How to bind a click event to a Canvas in Tkinter?

How to open a new window by clicking a button using Tkinter in python? [duplicate]

This question already has answers here:
How can I open a new window when the user clicks the button?
(2 answers)
Closed 6 years ago.
I want to make a gui application in python for that I was making this type of code.
I have already tired many codes but i was not able to make it up to the requirement.
What's stopping you from doing it, please refer the original post here. But basic code:
import Tkinter as tk
def create_window():
window = tk.Toplevel(root)
root = tk.Tk()
b = tk.Button(root, text="Create new window", command=create_window)
b.pack()
root.mainloop()

Python Tkinter removing disabled button overlay [duplicate]

This question already has an answer here:
tkinter color of disabled buttons / disabled optionmenus
(1 answer)
Closed 8 years ago.
In my Program I use a picture in a button. If I now disable this button with button.configure(state="disabled"), I get a white overlay over the whole button. Can I remove this overlay? If yes how? Thanks in advance. Here is an example code:
import Tkinter as tk
window = tk.Tk()
def disable():
button1.config(state="disabled")
button1=tk.Button(command=disable)
testbild=tk.PhotoImage(file="testbild.gif")
button1.image=testbild
button1.configure(relief="flat", image=testbild, height=180, width=180,
background="lightgreen", activebackground="lightgreen", bd=0)
button1.pack()
window.mainloop()
You may be able to change the color of the stipple by setting a background color at Button creation time:
button1=tk.Button(command=disable, bg='black')

Categories

Resources