Question

    import sys
from tkinter import *
def main():


    mtext = ment.get()
    mlabel2 = Label(top, text=mtext).pack()

def isbn():
    digits = [(11 - i) * num for i, num in enumerate(map(int, list()))]
    digit_11 = 11 - (sum(digits) % 11)
    if digit_11 == 10:
        digit_11 = 'X'    
    digits.append(digit_11)
    isbn_number = "".join(map(str, digits))
    label2 = Label(top, text = "Your ISBN number is",).pack()



top = Tk()
top.geometry("450x450+500+300")
top.title("Test")
button = Button(top,text="OK", command = isbn, fg = "red", bg="blue").pack()
label = Label(top, text = "Please enter the 10 digit number").pack()

ment= IntVar()

mEntry = Entry(top,textvariable=ment).pack()

Hello, I the code at the moment is a working stage, I just need a way of the results printing because at the moment it is not. I would also like the converter to work proper ally with 10 digits and the 11th digit being the number that the converter finds outs. Thanls

Était-ce utile?

La solution

Note how the button's command calls the function to perform your operation:

from tkinter import *


def find_isbn(isbn, lbl):
    if len(isbn) == 10:
        mult = 11
        total = 0
        for i in range(len(isbn)):
            total += int(isbn[i]) * mult
            mult -= 1
        digit_11 = 11 - (total % 11)
        if digit_11 == 10:
            digit_11 = 'X'
        isbn += str(digit_11)
        lbl.config(text=isbn)

top = Tk()
top.geometry("450x450+500+300")
top.title("Test")

button = Button(top, text="OK", command=lambda: find_isbn(mEntry.get(), mlabel2), fg="red", bg="blue")
button.pack()

label = Label(top, text="Please enter the 10 digit number")
label.pack()

mEntry = Entry(top)
mEntry.pack()

mlabel2 = Label(top, text='')
mlabel2.pack()

top.mainloop()

You also need to call .mainloop(), on your master widget to get the whole things started. It's also better to call .pack() on an object on a separate line. pack() and grid() return nothing so you won't be able to use other methods on the object once you do that.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top