문제

    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

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top