ich habe mein problem: "das auslesen einer 3GB großen Textdatei per Button abzubrechen"
gemäß euren tipps versucht umzusetzen.
aber kurz vorm ziel komm ich mal wieder nicht klar...
Code: Alles auswählen
#!/usr/bin/python
# -*- coding: utf-8 -*-
try:
# Tkinter for Python 2.xx
import Tkinter as tk
except ImportError:
# Tkinter for Python 3.xx
import tkinter as tk
import codecs
import os
from threading import Thread
from Queue import Queue
source_filename = "C:\Users\DMD-OL\Desktop\Handy-Datenbank\DATANORM\DATANORM.002"
TIME_STEP = 1000 # Milliseconds
LABEL_WIDTH = 3
LABEL_FONT = ('Helevetica', 20, 'bold')
def start():
if not root.running:
root.running = True
counter()
process_file(source_filename)
def counter():
if not root.running: return
root.after(TIME_STEP, counter)
def stop():
root.running = False
#######
#Auslesen einer 3GB großen Textdatei
#######
def process_file(source_filename):
# AN DIESER STELLE HÄTTE ICH GERN NACH JEDEM TIME_STEP DIE AKTUELLE AUSGABE VON "root.running" nach 1000 millisekunden
print root.running
# DAMIT ICH MIT
#while root.running:
# worker_queue = Queue()
# finished = object()
# def process(queue, line):
# queue.put(line)
# def read():
# with open(source_filename) as source:
# for line in source:
# queue = Queue()
# Thread(target = process, args=(queue, line)).start()
# worker_queue.put(queue)
# worker_queue.put(finished)
# Thread(target = read).start()
# for output in iter(worker_queue.get, finished):
# print output.get()
root = tk.Tk()
root.config(relief='groove', bd=2)
root.running = False
app = tk.Frame(root)
app.grid(padx=5, pady=5)
tk.Button(app, text="Start", command=start).pack(pady=2) #process_file(source_filename)
tk.Button(app, text="Stop", command=stop).pack()
root.mainloop()
