'^' and '$' regex characters not supported in find_text
rodneyboyd opened this issue · 3 comments
rodneyboyd commented
import tkinter as tk
from tkinter import *
from tkinter import ttk
import tkinterweb
import os.path
import sys
from sys import platform
def find1(e=None):
hits = html_frame.find_text('^c', select=1, ignore_case=True, highlight_all=True)
print('hits:', hits)
def find2(e=None):
hits = html_frame.find_text('c', select=1, ignore_case=True, highlight_all=True)
print('hits:', hits)
def main():
global window
window = tk.Tk()
window.title("Simple Browser")
global my_path
my_path = os.path.dirname(os.path.abspath(__file__))
if platform == 'win32':
my_path = my_path.replace('\\','/')
window.columnconfigure(0, weight=1)
my_frame = tk.Frame(window, width=300, height=350)
my_frame.pack_propagate(0)
v = Scrollbar(my_frame, orient='vertical')
v.pack(side=RIGHT, fill='y')
canvas = tk.Canvas(my_frame, yscrollcommand=v.set)
v.config(command=canvas.yview)
my_frame.grid(row=0, column=1, sticky=N+S+E+W)
my_frame.grid_propagate(0)
global html_frame
html_frame = tkinterweb.HtmlFrame(canvas, messages_enabled = False, width=300, height=350, vertical_scrollbar=False)
global url
url = 'file:///' + my_path + '/helptest3.html'
# print(url)
html_frame.grid_propagate(0)
html_frame.grid(row=0, column=0, sticky=N+S+E+W)
html_frame.load_file(url, force=False)
window.rowconfigure(0, weight=1)
canvas.pack()
window.bind('<Control-f>', find1)
window.bind('<Control-d>', find2)
window.mainloop()
if __name__ == "__main__":
main()
Sample file:
<html>
<head>
<title>Just a test</title>
</head>
<body>
<p>cat</p>
<p>black</p>
</body>
</html>
The first find operation (Ctrl+F) matches 0 hits and the second (Ctrl+D) matches 2 hits.
Andereoo commented
Great point. I changed the search flags to re.MULTILINE
. Let me know if it works!
rodneyboyd commented
It now works. Thanks!
Andereoo commented
Great; thanks for the suggestion!