def execute():
passw = choice2.get()
print(passw)
# pdf = Pdf.open(pdfFN, allow_overwriting_input=True)
# pdf.save(pdfFN, encryption=pikepdf.Encryption(user= "dog" , owner= "dog"))
# pdf.close()
window2.destroy()
def createPDF():
global choice1
choice1 = IntVar()
global choice2
choice2 = IntVar()
global choice3
choice3 = StringVar()
global pdfFN
filename = filedialog.askopenfilename(initialdir = "/",
title = "Select a File",
filetypes = (("Text files",
"*.docx"),
("all files",
"*.*")))
label_file_explorer.configure(text="File Selected: " + filename)
for i in range(len(filename)):
if(filename[i] == '.'):
pdfFN = filename[0:i+1] + "pdf"
break
convert(filename, pdfFN)
global window2
window2 = Tk()
window2.title('Datasheet Option Panel')
window2_width = 700
window2_height = 200
screen2_width = window2.winfo_screenwidth()
screen2_height = window2.winfo_screenheight()
center2_x = int(screen2_width/2 - window2_width / 2)
center2_y = int(screen2_height/2 - window2_height / 2)
window2.geometry(f'{window_width}x{window_height}+{center_x}+{center_y}')
window2.iconbitmap('/software/ablogo.ico')
window2.config(background = "white")
Label(window2,
text = "What would you like to do?",
width = 80, height = 3,
fg = "blue").place(x = 70, y = 0 )
# if(choice1.get()):
# pdf = Pdf.open(pdfFN, allow_overwriting_input=True)
# pdf.save(pdfFN, encryption=pikepdf.Encryption(user="user password", owner="owner password"))
# pdf.close()
ttk.Checkbutton(window2,
text='Password',
variable= choice1,
onvalue= 1 ,
offvalue= 0).place(x = 100, y = 120 )
ttk.Entry(window2, textvariable = choice3, font = ('calibre',10,'normal'), show = '*').place(x = 180, y = 120 )
ttk.Checkbutton(window2,
text='Watermark',
variable= choice2,
onvalue= 1 ,
offvalue= 0).place(x = 440, y = 120 )
button_submit = Button(window2,
text = "Submit", command = execute).place(x=620, y= 160)
window2.mainloop()发布于 2022-06-25 14:03:03
您提供的代码根本不起作用,所以很难相信使用Tkinter的范围出现问题时,由于某种原因,当我打印"passw“时,它仍然是0,而不管是否输入了校验按钮,但是.我不想在这里进一步讨论了。
下面的代码与tkinter和Python 3一起工作,并执行您希望它做的事情。它仍然有点混乱,不会在使用Tkinter的Python版本上运行,除非您将tkinter更改为Tkinter,并做一些其他更改以使其在旧的系统上运行,但是.如果有必要,只需自己对代码进行小的调整,使其为您运行,并享受将输入到用户对话框小部件中的值打印到输出:
from tkinter import *
from tkinter import filedialog
import tkinter.ttk as ttk
# pwd = '/'
import os ; pwd = os.popen('pwd').read()
def convert(filename, pdfFN):
print('Converting', filename, 'to', pdfFN)
def execute():
passwYesNo = chckbttn_passw_value.get()
wmarkYesNo = chckbttn_wmark_value.get()
user_entry = user_entry_value.get()
print(f'{passwYesNo=}, {wmarkYesNo=}, {user_entry=}')
# pdf = Pdf.open(pdfFN, allow_overwriting_input=True)
# pdf.save(pdfFN, encryption=pikepdf.Encryption(user= "dog" , owner= "dog"))
# pdf.close()
root.destroy()
def createPDF():
global root ; root = Tk()
root.title('Datasheet Option Panel')
window_width = 700 ; screen_width = root.winfo_screenwidth()
window_height = 200 ; screen_height = root.winfo_screenheight()
center_x = int(screen_width / 2 - window_width / 2)
center_y = int(screen_height / 2 - window_height / 2)
root.geometry(f'{window_width}x{window_height}+{center_x}+{center_y}')
# root.iconbitmap('/software/ablogo.ico')
root.config(background = "white")
global chckbttn_passw_value ; chckbttn_passw_value = IntVar()
global chckbttn_wmark_value ; chckbttn_wmark_value = IntVar()
global user_entry_value ; user_entry_value = StringVar()
global pdfFN
# """
filename = filedialog.askopenfilename(initialdir = pwd,
title = "Select a File",
filetypes = (("Text files", "*.docx"), ("all files", "*.*")))
for i in range(len(filename)):
if(filename[i] == '.'):
pdfFN = filename[0:i+1] + "pdf"
break
# """
# filename = "selectedDocument.docx"
# pdfFN = "selectedDocument.pdf"
convert(filename, pdfFN)
label_file_explorer = Label(root, text = "What would you like to do?",
width = 68, height = 3, fg = "blue")
label_file_explorer.place(x = 70, y = 0 )
# if(choice1.get()):
# pdf = Pdf.open(pdfFN, allow_overwriting_input=True)
# pdf.save(pdfFN, encryption=pikepdf.Encryption(user="user password", owner="owner password"))
# pdf.close()
label_file_explorer.configure(text="File Selected: " + filename)
ttk.Checkbutton(root, text='Password',
variable=chckbttn_passw_value,
onvalue= 1, offvalue= 0).place(x=100,y=120)
ttk.Checkbutton(root, text='Watermark',
variable=chckbttn_wmark_value,
onvalue= 1, offvalue= 0).place(x=440,y=120)
ttk.Entry(root, textvariable=user_entry_value,font=('calibre',10,'normal'),
show ='*').place(x=180,y=120 )
Button(root, text="Submit", command=execute).place(x=620,y=160)
label_file_explorer.configure(text="File Selected: " + filename)
root.mainloop()
createPDF()https://stackoverflow.com/questions/72735894
复制相似问题