Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 help with a number sequence generator
#1
Hi
Im trying to do a number sequence generator. where i got 4 textboxes where i can chose the numbers it will do a sequens between. say i chose 401 in textbox1 and 405 in textbox2 and 501 in textbox3 and in textbox4 505 the result print will be like

example1
401-501
501-401
402-502
502-402
403-503
503-403
and so on....

The code i wrote now is meant to print a sequence like example 2. But its doesent work. i get strange number sequences.

example2
401-501
402-502
and so on....

But  i dont know if its possible to do it like example1 which i would like to have it like. 
from tkinter import *
import tkinter as tk

class StatusBar(Frame):
    def __init__(self, master):
        Frame.__init__(self, master)
        self.label = Label(self, bd=1, relief=SUNKEN, anchor=W)
        self.label.pack(fill=X)

    def set(self, format, *args):
        self.label.config(text=format % args)
        self.label.update_idletasks()

    def clear(self):
        self.label.config(text="")
        self.label.update_idletasks()
        
    def funktion(self):
        value1 = (a1.get())
        value2 = (a2.get())
        value3 = (b1.get())
        value4 = (b2.get())
        for a in range(value1, value2+1):
            for b in range(value3, value4+1):  
                print('{}-{}\n'.format(a, b))   


        
if __name__ == "__main__":

    root = Tk()

    Frame(root, width=400, height=200).pack()
    status = StatusBar(root)
    status.pack(side=BOTTOM, fill=X)
    
    
    a1 = IntVar()
    a2 = IntVar()
    b1 = IntVar()
    b2 = IntVar()
    
    sida1från_entry = tk.Entry(root, font=('Helvetica', 12, 'bold'), textvariable=a1)
    sida1från_entry.pack( fill=X)
    sida1till_entry = tk.Entry(root, font=('Helvetica', 12, 'bold'), textvariable=a2)
    sida1till_entry.pack(fill=X)

    sida2från_entry = tk.Entry(root, font=('Helvetica', 12, 'bold'), textvariable=b1)
    sida2från_entry.pack( fill=X)
    sida2till_entry = tk.Entry(root, font=('Helvetica', 12, 'bold'), textvariable=b2)
    sida2till_entry.pack(fill=X)
    
    button1 = tk.Button(root, text="Make",  command=status.funktion, width = 5)
    button1.pack( fill=X)

    
    
    root.update()

    root.mainloop()
Quote
#2
Sorry for the late reply, I did modify your code. Though not the best but works:
def funktion(self):
        value1 = (a1.get())
        value2 = (a2.get())
        value3 = (b1.get())
        value4 = (b2.get())
        steps =  0
        for a in range(value1-1, value2):
            print('{}-{}\n'.format(a+1, value3 + steps))
            print('{}-{}\n'.format(value3 + steps, a+1))
            steps +=1
Modify your
def funktion(self)
and you will get your desired output.

401-501

501-401

402-502

502-402

403-503

503-403

404-504

504-404

405-505

505-405
.......
Quote
#3
(Aug-26-2017, 08:14 PM)deaspo Wrote: Sorry for the late reply, I did modify your code. Though not the best but works:
def funktion(self):
value1 = (a1.get())
value2 = (a2.get())
value3 = (b1.get())
value4 = (b2.get())
steps = 0
for a in range(value1-1, value2):
print('{}-{}\n'.format(a+1, value3 + steps))
print('{}-{}\n'.format(value3 + steps, a+1))
steps +=1
Modify your
def funktion(self)
and you will get your desired output.

401-501

501-401

402-502

502-402

403-503

503-403

404-504

504-404

405-505

505-405
.......

Thank you works like a charm.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Repeating same number in sequence Rudinirudini 6 737 Oct-28-2018, 07:44 PM
Last Post: DeaD_EyE
  receive from a generator, send to a generator Skaperen 9 1,230 Feb-05-2018, 06:26 AM
Last Post: Skaperen

Forum Jump:


Users browsing this thread: 1 Guest(s)