标签: tkinter

如何在 Tkinter 中删除图像按钮的边框?

我知道如何删除 Tkinter 按钮和图像的边框。它的完成方式与其他所有事情的完成方式几乎完全相同

borderwidth=0
Run Code Online (Sandbox Code Playgroud)

我需要帮助,如果为什么,即使我将其放入小部件的“设计参数”中,它仍然有边框。

我的代码如下。

# Imports the tkinter library.
from tkinter import *
from tkmacosx import Button


selectedBackground = "black"
selectedForeground = "#22fd35"

root = Tk()
root.configure(bg=selectedBackground)

def openCipher():
    print("open cipher")


def openDecipher():
    print("open decipher")

cipherButton = Button(root, text="  Cipher  ", padx=40, pady=20, command=openCipher, borderwidth=0, background=selectedBackground, foreground=selectedForeground, highlightbackground=selectedForeground)
cipherButton.grid(row=1, column=0)
decipherButton = Button(root, text="Decipher", padx=40, pady=20, command=openDecipher, borderwidth=0, background=selectedBackground, foreground=selectedForeground, highlightbackground=selectedForeground).grid(row=1, column=2)
spacer1 = Label(root, text="     ", padx=10, pady=1, background=selectedBackground, foreground=selectedForeground, highlightbackground=selectedForeground).grid(row=4, column=1)
quitButton = Button(root, text="Exit d3cryptt", …
Run Code Online (Sandbox Code Playgroud)

python tkinter tkinter-label tkinter-button

0
推荐指数
1
解决办法
704
查看次数

.png 是 python 的 tkinter 模块中唯一可接受的格式吗?

我尝试插入格式为 .jpg 的图片作为 PhotoImage

但每次我尝试运行该程序时,都会出现以下错误:

无法识别图像文件中的数据

但是 .png 图片永远不会发生这种情况,这让我想知道 .png 是否是 tkinter 中唯一可接受的格式?

python image tkinter photoimage tkinter-photoimage

0
推荐指数
1
解决办法
342
查看次数

在 Python Tkinter 中,button.configure() 命令未在 while 循环内运行

我正在尝试根据 while 循环确定的值来配置按钮,turn该值由 while 循环确定game_over

while 循环干扰了 tkinter 的主循环。我似乎无法找到解决这个问题的方法。

这是代码。

from tkinter import *
connect = Toplevel()

col1 = Button(connect, width=10, height=4, text=" ")
col1.grid(row=0, column=1)

game_over = False
turn = 0

while not game_over:
    if turn == 0:
        col1.configure(bg="#FE6869")
        x=input("Enter something")
        if x=="yes":
            game_over=True
        else:
            continue   
    else:       
        col1.configure(bg="#FFFC82")
        x=input("Enter something")
        if x=="no":
            game_over=True
        else:
            continue
    turn += 1
    turn = turn % 2

connect.mainloop()
Run Code Online (Sandbox Code Playgroud)

python tkinter button while-loop

0
推荐指数
1
解决办法
52
查看次数

在 Python 中使用 Tkinter GUI 时标题无法正确显示

我目前正在尝试使用 Tkinter 包使用 Python 来学习制作简单的 GUI。

我为待办事项列表编写了这个程序:


import tkinter
import tkinter.messagebox
import pickle

root = tkinter.Tk()
root.title = ("To Do List")

def add_task():
    task = entry_task.get()
    if task not in ["", "Do nothing"]:
        listbox_tasks.insert(tkinter.END, task)  
        entry_task.delete(0, tkinter.END)
    else:
        tkinter.messagebox.showwarning(title="Warning!", message="Doing nothing is not an option!.")

def delete_task():
    try:
        task_index = listbox_tasks.curselection()[0]
        listbox_tasks.delete(task_index)
    except:
        tkinter.messagebox.showwarning(title="Warning!", message="You need to select a task to delete.")

def load_tasks():
    try:
        tasks = pickle.load(open("Aufgaben.txt", "rb"))  # reading binary
        listbox_tasks.delete(0, tkinter.END)
        for task in tasks:
            listbox_tasks.insert(tkinter.END, task) …
Run Code Online (Sandbox Code Playgroud)

python user-interface tk-toolkit tkinter button

0
推荐指数
1
解决办法
87
查看次数

TKinter 条件失败

作为菜鸟,我在尝试学习新技能时弄乱了一些代码,现在我正在 Python 3.x 上学习 TKinter。一切都很好,直到有条件,但我正在尝试启动一些简单的东西,例如“用户访问界面”模拟器。只是经典的 if True 条件。

\n

因此,作为用户,您需要介绍您的用户名和密码。我只是做了密码限制以使示例更容易。但由于某种原因,总是当我写出正确的密码时,条件判断条件为False并执行else。

\n

我尝试更改这个词,甚至制作一个“if password_input is str:”来检查条件是否有效的最简单方法,但仍然收到错误。

\n

在此先感谢您的帮助。代码如下:

\n
from tkinter import *\n\nROOT = Tk()\nROOT.geometry("500x300+50+50")\nROOT.config(bg="grey")\nROOT.title("Ventana de acceso")\n\nuser_tag = Label(text="Usuario: ")\nuser_tag.grid(row=0, column=0)\nuser_tag.config(bg="grey", font=("Arial", 16))\n\npassword_tag = Label(text="Contrase\xc3\xb1a: ")\npassword_tag.grid(row=1, column=0)\npassword_tag.config(bg="grey", font=("Arial", 16))\n\nuser_input = Entry()\nuser_input.grid(row=0, column=1)\nuser_input.config(bg="red", font=("Comic Sans", 16))\nuser_input.insert(0, "Introduce tu usuario...") # Olvid\xc3\xa9 poner el argumento de posici\xc3\xb3n\n\npassword_input = Entry()\npassword_input.grid(row=1, column=1)\npassword_input.config(bg="red", font=("Comic Sans", 16), show="*")\npassword_input.insert(0, "***********")\n\nspace_0 = Label(text=" ")\nspace_0.grid(row=3)\nspace_0.config(bg="grey")\n\nspace_1 = Label(text=" ")\nspace_1.grid(row=4, column=0)\nspace_1.config(bg="grey")\n\nspace_2 = Label(text=" ")\nspace_2.grid(row=2, column=0)\nspace_2.config(bg="grey")\n\ndef click_check_button():\n    if password_input == "python":\n        access_granted = …
Run Code Online (Sandbox Code Playgroud)

python if-statement tkinter python-3.x tkinter-entry

0
推荐指数
1
解决办法
46
查看次数

导入 tkinter:模块列表

导入tkinter不会导入一些基本且有用的模块,例如messagebox,如下所述:tkinter.messagebox.showinfo 并不总是有效

我如何检查哪些模块是实际导入的,哪些模块import tkinter可以通过显式导入(例如from tkinter import messagebox)来导入?

python import tkinter tkmessagebox python-3.x

-1
推荐指数
1
解决办法
1855
查看次数

如何使用 tkinter 将功能键绑定到键盘中的键

我想创建一个通过按下带有命令 ( b = Button(command = a))的按钮触发的函数,该按钮也能够接受来自 bind 命令的调用。问题是 bind 命令发送一个变量(事件)而 command 不发送。我遇到的另一个问题是我无法弄清楚如何将功能链接到计算机上的物理按键

我试图b.bind('a',func)链接物理键并检查与输入键的绑定

from tkinter import *
def func():
    print("meow")

main = Tk()
bRoll = Button(text = "Hello", command = func)
bRoll.bind('r',func)
bRoll.bind('<Enter>',func)
bRoll.pack()
main.mainloop()
Run Code Online (Sandbox Code Playgroud)

这似乎不起作用,因为它什么也没做,我尝试绑定到Enter键 ( <Enter>) 以查看会发生什么,它打印了一个错误,因为它想向其发送事件func但它无法接受它。

python tkinter key-bindings

-1
推荐指数
1
解决办法
6547
查看次数

TkInter 错误:没有显示名称和 $DISPLAY 环境变量

我正在 Repl.it 上使用TkInter并且遇到了一个问题,这是我的代码:

from tkinter import *
import tkinter as tk

root = tk.Tk()
root.geometry('400x400')
Run Code Online (Sandbox Code Playgroud)

我遇到了这个错误:

Traceback (most recent call last):
  File "main.py", line 4, in <module>
    root = tk.Tk()
  File "/usr/local/lib/python3.7/tkinter/__init__.py", line 202
3, in __init__
    self.tk = _tkinter.create(screenName, baseName, className,
interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: no display name and no $DISPLAY environment
variable
Run Code Online (Sandbox Code Playgroud)

我该如何解决这个问题?

python tkinter python-3.x

-1
推荐指数
1
解决办法
6132
查看次数

有什么方法可以通过右键单击在 Tkinter 列表框中选择一个项目?

我希望能够使用左键单击或右键单击在 Tkinter 列表框中选择一个项目。有什么方法可以绑定"<button-3>"到某种选择项目的函数,或者在将鼠标悬停在列表框上时从右键单击调用左键单击?

python user-interface tkinter

-1
推荐指数
1
解决办法
473
查看次数

Tkinter 使用鼠标在画布上调整矩形的大小

我想在 Tkinter 中为我的研究项目创建一个简单的 GUI 图像标签工具。目前,我有可以从目录加载图像并允许我绘制多个边界框的工作代码。我想修改代码,以便在单击矩形 BB 时可以使用鼠标调整它的大小。我在网上搜索过,找不到任何资源来做到这一点。有人可以帮助我了解如何做到这一点吗?

from tkinter import *
from tkinter import filedialog
from tkinter import messagebox
from tkinter import ttk
from PIL import Image, ImageTk
import os
import glob
import random

# colors for the bboxes
COLORS = ['red', 'blue','pink', 'cyan', 'green', 'black']
# image sizes for the examples
SIZE = 256, 256

class LabelTool():
    def __init__(self, master):
        # set up the main frame
        self.parent = master
        self.parent.title("LabelTool")
        self.frame = Frame(self.parent)
        self.frame.pack(fill=BOTH, expand=1)
        self.parent.resizable(width = FALSE, height …
Run Code Online (Sandbox Code Playgroud)

python tkinter

-1
推荐指数
1
解决办法
320
查看次数