小编Mos*_*she的帖子

从python tkinter中的Checkbox获取输入?

我正在尝试使用python和tkinter来创建一个程序,该程序运行已在复选框中选中的程序.

import sys
from tkinter import *
import tkinter.messagebox
def runSelectedItems():
    if checkCmd == 0:
        labelText = Label(text="It worked").pack()
    else:
        labelText = Label(text="Please select an item from the checklist below").pack()

checkBox1 = Checkbutton(mGui, variable=checkCmd, onvalue=1, offvalue=0, text="Command  Prompt").pack()
buttonCmd = Button(mGui, text="Run Checked Items", command=runSelectedItems).pack()
Run Code Online (Sandbox Code Playgroud)

这是代码,但我不明白为什么它不起作用?

谢谢.

python checkbox tkinter input

7
推荐指数
1
解决办法
2万
查看次数

python3打开文件和阅读行

你能解释一下这段代码中发生了什么吗?我似乎不明白你如何打开文件并在for循环中逐行读取而不是所有句子.谢谢

假设我在文档文件中有这些句子:

cat:dog:mice
cat1:dog1:mice1
cat2:dog2:mice2
cat3:dog3:mice3
Run Code Online (Sandbox Code Playgroud)

这是代码:

from sys import argv

filename = input("Please enter the name of a file: ")
f = open(filename,'r')

d1ct = dict()
print("Number of times each animal visited each station:")
print("Animal Id           Station 1           Station 2")

for line in f:
     if '\n' == line[-1]:
          line = line[:-1]
     (AnimalId, Timestamp, StationId,) = line.split(':')
     key = (AnimalId,StationId,)
     if key not in d1ct:
          d1ct[key] = 0
     d1ct[key] += 1
Run Code Online (Sandbox Code Playgroud)

python-3.x

6
推荐指数
2
解决办法
3万
查看次数

更改 Tkinter 的 Checkbutton 中复选框相对于文本的位置

如何更改文本相对于 Tkinter 复选框的位置Checkbutton

默认情况下,文本位于复选框的右侧。我想更改它,因此文本位于复选框的左侧或上方。

我知道这可以通过创建一个Label包含所需文本的文本并将两者巧妙地放置在彼此附近来完成,但我宁愿避免这种方法。

一些示例代码:

from Tkinter import * 
root = Tk()
Checkbutton(root, text="checkButon Text").grid()
root.mainloop()
Run Code Online (Sandbox Code Playgroud)

python tkinter python-2.7

6
推荐指数
1
解决办法
9557
查看次数

将 Tkinter 复选按钮文本字符向左对齐

我正在使用 Python 2.7 来显示 2 Checkbuttons。如果我使用justify = LEFT它会显示错误"global name 'LEFT' is not defined"

class simple_ap(Tkinter.Tk):
    def __init__(self,parent):
        Tkinter.Tk.__init__(self,parent)
        self.parent = parent
        self.initialize()

    def initialize(self):


        Checkbutton = Tkinter.Checkbutton(self,text='All_1',width = 50,justify = LEFT)
        Checkbutton.grid(column = 0, row = 0)

        Checkbutton = Tkinter.Checkbutton (self,text='To_check_for_the_space_between_brackets',width = 50)
        Checkbutton.grid(column = 0, row = 8)

if __name__ == "__main__":
    app = simple_ap(None)
    app.title('my_app')
    app.mainloop()
Run Code Online (Sandbox Code Playgroud)

这是使用“justify”的正确方法吗?我在http://www.tutorialspoint.com/python/tk_frame.htm 工作

python tkinter python-2.7

4
推荐指数
1
解决办法
6928
查看次数

禁用Python请求导入模块的SSL验证

我正在运行一个Python脚本,该脚本使用该requests包来发出Web请求.但是,Web请求通过具有自签名证书的代理进行.因此,请求引发以下异常:

requests.exceptions.SSLError: ("bad handshake: Error([('SSL routines', 'SSL3_GET_SERVER_CERTIFICATE', 'certificate verify failed')],)",)

我知道通过传递可以在我自己的代码中禁用SSL验证verify=False,例如:requests.get("https://www.google.com", verify=False).我也知道如果我有证书包,我可以设置REQUESTS_CA_BUNDLECURL_CA_BUNDLE环境变量指向那些文件.但是,我没有可用的证书包.

如何在不编辑代码的情况下禁用外部模块的SSL验证?

python ssl python-requests

4
推荐指数
1
解决办法
7157
查看次数

在python中按freq排序单词

import sys
def candidateWord():
   filePath = "sample.txt"
   file = open(filePath,'r')
   word_count = {}
   for line in sys.stdin.readlines():
         for word in line.split():
            #words = word.lower()
            words = word.strip('!,.?1234567890-=@#$%^&*()_+').lower()
            word_count[words] = word_count.get(words,0) + 1

         for key in word_count.keys():
            #sorted(word, key = str,lower)
            print (str(key)+' '+str(word_count[key]))

candidateWord()
Run Code Online (Sandbox Code Playgroud)

我如何使用我已经拥有的频率按照频率对文本文件中的单词进行排序?

文本文件(sample.txt)包含以下内容: How are you How are you I am good. HBHJKOLDSA How

我的愿望输出应该是:

how 3
am 2
are 2
i 2
you 2
good 1
hbhjkoldsa 1
Run Code Online (Sandbox Code Playgroud)

我在python 3中工作.

python sorting list python-3.x

0
推荐指数
1
解决办法
142
查看次数