标签: tkinter

在文本中查找字符串位置(Python、TkInter)

如何在我的文本中找到特定文本字符串的位置?

例如,我有文本“Lorem ipsum dolor sat amet, consectetur adipiscing elit.”,当我搜索“ipsum”时,我想找出它的位置。

if "ipsum" in text:
    print position


else:
    pass
Run Code Online (Sandbox Code Playgroud)

我正在寻找的位置类似于“1.6”如果我想更改文本的颜色,它看起来像这样:

text.tag_add("foo", "1.28", "1.39")
Run Code Online (Sandbox Code Playgroud)

然后为了改变我搜索过的文本的颜色,我需要以某种方式获得它的位置,对吗?我可能是错的,但我正在寻找一些示例或指导。谢谢!:)

python tk-toolkit tkinter

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

Python askdirectory()

文件移动基于上次更新.仅使用按钮3,我在目录末尾缺少斜杠.这会导致路径与我尝试移动的文本文件合并:

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Python34\lib\tkinter\__init__.py", line 1482, in __call__
    return self.func(*args)
  File "C:/Python34/check2.py", line 30, in fileMove
    if os.stat(src).st_mtime > now - 1 * 86400:
FileNotFoundError: [WinError 2] The system cannot find the file specified: 'C:/Somewhere/filenametextfile'
Run Code Online (Sandbox Code Playgroud)


import shutil, sys, time, os
import tkinter as tk
from tkinter import *
import tkinter.filedialog
root = Tk()

def fileMove():
        sourcePath = filedialog.askdirectory()
        receivePath = filedialog.askdirectory()
        source = sourcePath
        dest = receivePath
        files = os.listdir(source) 

        now = …
Run Code Online (Sandbox Code Playgroud)

python tkinter taskdialog

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

Python tkinter 导入错误

from tkinter import *
from tkinter import messagebox

root= Tk()
root.mainloop()
Run Code Online (Sandbox Code Playgroud)

错误:

...回溯(最近一次调用最后一次):文件“C:\Users\Lee\Desktop\Python items\tkinter.py”,第 1 行,导入 tkinter as Tk 文件“C:\Users\Lee\Desktop\Python” items\tkinter.py”,第 2 行,来自 tkinter import messagebox ImportError:无法导入名称“messagebox”

[25.248秒内完成]我不知道为什么messagebox不会导入?

import tkinter python-3.x

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

如何在tkinter中绘制对角线箭头?

我需要从指向黄色框的蓝色和绿色框绘制两个箭头。我尝试使用 create_line 绘制对角线,但没有用。任何人都可以建议我可以绘制这些箭头的任何方法。使用 create_line 时的错误消息是:AttributeError: '_tkinter.tkapp' object has no attribute 'create_line'

from tkinter import *
import tkinter as tk


window = Tk()
window.geometry("900x500")
window.configure(background='red')
window.title("Theoretical")

label1 = Label(window, text="Hess' cycle of combustion", fg="black", bg="red", font=("Comic Sans MS", 20))
label1.pack()    

text1 = Text(window, width=20, height = 1, bg= "blue")
text1.place(x=200, y=100)

window.create_line(0, 0, 200, 100)
window.create_line(0, 100, 200, 0, fill="white")

text2 = Text(window, width=20, height = 1, bg= "green")
text2.place(x=520, y=100)

text3 = Text(window, width=20, height = 1, bg= "yellow")
text3.place(x=370, …
Run Code Online (Sandbox Code Playgroud)

python tkinter tkinter-canvas

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

tkinter:在每行文本旁边的文本框中动态插入按钮

问题:

我有一个 for 循环,它将文本添加到文本框。我想要一个按钮位于文本之后、每次迭代在文本框中结束之前的最右侧。

另外,是否可以将某种标签(即其之前的文本)分配给按钮?因此,对于每次迭代,按钮都会调用一个函数并在其之前传递文本。

预期图像:

在此输入图像描述

python tkinter python-3.x

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

Tkinter或TTK GUI编程?

我是python编程的初学者,必须做一个必须在学校提交的项目。我在一个月前发现了tkinter和ttk,并且想知道哪种代码更好。

我程序的目的是使其与用户交互,并使其看起来尽可能现代。如果您能告诉我tkinter相对ttk的优势,反之亦然,以及我建议您使用哪一种,我将不胜感激。

该计划的目的是与某个地点的居民进行互动,并允许他访问该地点的不同功能以及类似的东西。

python tkinter ttk python-2.7

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

为什么我的tkinter按钮不显示,如果没有安装模块中的所有组件,该如何安装?

#snakes and ladder
from tkinter import * #pygame is the module that has collections of functions that is used to create a window import everything from tkinter
import time

class window(Frame): #Frame comes from tkinter is what you think as a window

    def __init__(self, master = None):#The master widget defines the settings upon initialisation
        Frame.__init__(self, master) #This is called the frame class that has been built in python
        self.master = master

    def __init__window(self):  #creation of the init window

        self.master.title("Reagan Kambayi") …
Run Code Online (Sandbox Code Playgroud)

python tkinter

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

如何使用Tkinter创建导入文件按钮?

因此,您知道例如在Windows上使用记事本时想要打开旧文件的方式吗?您单击文件,然后打开,然后将打开一个文件对话框,您可以选择所需的文件,程序将显示其内容。

基本上,我想在Python中创建一个可以完成此操作的按钮。

这是我按钮的功能-

def UploadAction():
    #What to do when the Upload button is pressed
    from tkinter import filedialog
Run Code Online (Sandbox Code Playgroud)

当我单击分配给该操作的按钮时,什么也没有发生,没有错误,没有崩溃,只是什么也没有。

python tkinter

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

如果语句在 Python 3 中无法正常工作

当分数大于或等于 5 时,我试图打印出一个字符串,但它不会打印。我在这里做错了什么?

from tkinter import *

top = Tk()
top.geometry("1000x720")

Score = 0

var = StringVar()
sline = Label(top, textvariable=var)
sline.place(x = 100, y = 395)
var.set("Score: ")

scorevar = StringVar()
label = Label(top, textvariable=scorevar)
label.place(x = 140, y = 395)
scorevar.set("0")



def getscore():
    global Score
    Score = Score + 1
    scorevar.set(Score)
    print(Score)

bclick = Button(top, fg='white', bg='RoyalBlue3', activebackground='azure', highlightcolor='azure', bd=4, padx=10, pady=5, text = "Click!", command = getscore)
bclick.place(x = 100,y = 350)

if Score >= 5:
    print("Hey, …
Run Code Online (Sandbox Code Playgroud)

python if-statement tkinter python-3.x

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