Python Tkinter removing disabled button overlay [duplicate] - python

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')

Related

How can I detect if a user click a tkinter button? [duplicate]

This question already has answers here:
How to handle a click button event in python module tkinter
(2 answers)
Closed 2 years ago.
Here is my code!
///
from tkinter import *
import os
import pygame
os.system(‘clear’)
#Window Setup
root = Tk()
root.title(‘cottontail’)
root.geometry(‘800x600’)
frame = Frame(root)
title_screen = Label(root, text = “Choose your rabbits name!”)
title_screen.pack()
name = Text(root, width=10 , height=3)
name.pack()
confirm_name = Button(root, text= “Conirm?”, width = 5, height=3)
root.mainloop()
///
My objective is to take the input the user puts in the text box to make a label in a pygame window with that name. I figured that a button would be an easy way to confirm the name and open the pygame screen. If this makes any sense to you it would really be appreciated if you could help me. Hope you have a good night!
Thanks in advance!
I'm not familiar with tkinter as I'm a PyQt dev, but I can help with your question as the logic behind both of them are same.
You can make a function that is called by the button whenever its clicked, and then, inside that function definition, do whatever you want.
Here's the website that explains this in detail -
https://www.delftstack.com/howto/python-tkinter/how-to-get-the-input-from-tkinter-text-box/

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 to add a scrollbar to a tkinter window? [duplicate]

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.

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 remove small border from fullscreen canvas in Tkinter [duplicate]

This question already has an answer here:
How to get rid of widget border?
(1 answer)
Closed 5 years ago.
When using a fullscreen canvas, such as in the following code:
from tkinter import *
root = Tk()
root.attributes("-fullscreen", True)
canvas = Canvas(root, background = "red") # I use a red background for visibility.
canvas.pack(fill = BOTH, expand = True)
I get a small (2 pixel) border around my entire screen. This happens on any computer I test the code on.
Is there a way I can remove this border, as in have the canvas fill in the entire screen up to the very edge?
Image of my full screen, with the fullscreen canvas
Thanks
Set this option to zero:
canvas = Canvas(root, background="red", highlightthickness=0)
Check the documentation to find the full list of options. It can help you to resolve many similar problems.

Categories

Resources